\chapter{Survival Data and the Kaplan-Meier Curve \label{chapter:km}}

We have already investigated supervised learning models and hypothesis tests in cases where the outcome of interest is a category or number. But what if the outcome is a \emph{time duration}? For example, what if we're comparing the effects of two treatments and our outcome is the time between treatment administration and disease progression?

Data where the outcome is a time duration are very common in clinical data science and are called \textbf{time-to-event} data or \textbf{survival data}. The field of \textbf{survival analysis} develops methods to analyze and interpret such data. We will examine one such method today and many more in subsequent chapters.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{Example: Ovarian Cancer Survival Dataset \label{section:ovarian}}

Today we'll examine some data from a study of ovarian cancer\footnote{The dataset comes from the \texttt{survival} package in R and is labeled \texttt{ovarian}. The original study is Edmonson JH \emph{et al}, ``Different chemotherapeutic sensitivities and host factors affecting prognosis in advanced ovarian carcinoma versus minimal residual disease'', \emph{Cancer Treatment Reports}, 63(2): 241-247; 1979.}. The dataset contains information on $26$~women. The variables are:

{\small
\begin{itemize}
\item \texttt{futime}: The number of days from enrollment in the study until death or censoring, whichever came first
\item \texttt{fustat}: An indicator of death (1) or censoring (0)
\item \texttt{age}: The patient's age in years at the time of treatment administration
\item \texttt{resid.ds}: Residual disease present at the time of treatment administration (1 = no, 2 = yes)
\item \texttt{rx}: Treatment group (1 = cyclophosphamide, 2 = cyclophosphamide + adriamycin)
\item \texttt{ecog.ps}: A measure of performance score or functional status at the time of treatment administration, using the Eastern Cooperative Oncology Group's (ECOG) scale. It ranges from 0 (fully functional) to 4 (completely disabled). Level 4 subjects are usually considered too ill to enter a randomized trial such as this. The patients in this dataset are all at Levels 1 and 2.
\end{itemize}
}

\noindent Here is a histogram of the follow-up times (\texttt{futime}) in days, colored according to whether the patient died or was censored (\texttt{fustat}):

\begin{center}
\includegraphics[width=0.7\textwidth]{img/cs-ovarian-futime.png}
\end{center}

\noindent And here is the same graph colored by treatment group (\texttt{rx}):

\begin{center}
\includegraphics[width=0.7\textwidth]{img/cs-ovarian-futime2.png}
\end{center}

Now, imagine that we want to study the effect of the treatment group (\texttt{rx}) on the outcome of death or no death (1 = death, 0 = no death). We could think of this as a classification problem with only a single feature: treatment group. Unfortunately, this method of analyzing time-dependent data is fraught with problems:

\begin{enumerate}
\item How do you choose the time horizon at which to evaluate mortality?
\item How do you handle people who dropped out of the study before that time?
\end{enumerate}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{Definitions}

\textbf{Censoring} occurs when the event of interest in a time-to-event analysis is not observed. It is a form of missing data problem (see Chapter~\ref{chapter:missingdata}) and can be caused by a variety of factors, including inconsistencies in follow-up, the study's ending before all subjects have experienced the event, or a lack of knowledge about when, exactly, the event occurred. The type of censoring represented in the \texttt{ovarian} dataset is called \textbf{right-censoring}. We will focus on right-censoring today and investigate other types later.
\begin{quote}
\textbf{Right censoring:} A situation that arises when the event of interest has not occurred by the end of the follow-up period. This may be because (a) the study itself ends, (b) a patient is lost to follow-up during the study period, or (c) a patient experiences a different event that makes further follow-up impossible\footnote{For more information, please see Clark TG \emph{et al}, ``Survival Analysis Part I: Basic Concepts and First Analyses'', \emph{British Journal of Cancer}, 89, 232--238; 2003.}.
\end{quote}

Survival data are generally described using two probabilities, called the survival and hazard.
\begin{quote}
\textbf{Survival:} Also called the \textbf{survival function} or \textbf{survival probability} and abbreviated $S(t)$, this is the probability that an individual survives to time $t$ (i.e., does not experience the event by time $t$).\\[5mm]
\textbf{Hazard:} Usually denoted by $h(t)$ or $\lambda(t)$, this is the probability that an individual who has not yet experienced the event at time $t$ experiences it at that exact time. In other words, it is the instantaneous event rate for an individual who has already survived to time $t$.
\end{quote}

We will focus on the survival function now and learn more about the hazard later.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{The Kaplan-Meier Estimator}

The \textbf{Kaplan-Meier estimator} is a nonparametric estimate of the survival function, usually represented graphically by a \textbf{Kaplan-Meier curve}\footnote{It can be shown mathematically that the Kaplan-Meier estimator is the maximum likelihood estimator (see Chapter~\ref{chapter:mlebasics}) of the survival function in the case of censoring.}. The Kaplan-Meier estimator looks like this:
$$ \hat{S}(t) = \prod_{j|t_j \leq t} \frac{n_j - d_j}{n_j} $$
where $d_j$ is the number of subjects who fail at time $t_j$ and $n_j$ is the number of subjects at risk just prior to $t_j$. Here is a Kaplan-Meier curve for the \texttt{ovarian} dataset. The little ``+'' signs correspond to censoring events.
\begin{center}
\includegraphics[width=0.6\textwidth]{img/ovarian-km-curve.png}
\end{center}
And here are Kaplan-Meier curves for the two treatment groups separately:
\begin{center}
\includegraphics[width=0.6\textwidth]{img/ovarian-km-curve-rx.png}
\end{center}
\vspace{5mm}

\begin{question}{question:kmo1}
Here are the raw data from treatment group $1$ of the \texttt{ovarian} dataset. Using these data, fill in the remaining cells of the table below.
{\small
\begin{center}
\begin{tabular}{rlrr}
  \toprule
 & rx & futime & fustat \\
  \midrule
  1 & 1 & 59 & 1 \\
  2 & 1 & 115 & 1 \\
  3 & 1 & 156 & 1 \\
  4 & 1 & 268 & 1 \\
  5 & 1 & 329 & 1 \\
  6 & 1 & 431 & 1 \\
  7 & 1 & 448 & 0 \\
  8 & 1 & 477 & 0 \\
  9 & 1 & 638 & 1 \\
  10 & 1 & 803 & 0 \\
  11 & 1 & 855 & 0 \\
  12 & 1 & 1040 & 0 \\
  13 & 1 & 1106 & 0 \\
  \bottomrule
\end{tabular}
\end{center}
}
\vspace{-5mm}
{\small
\begin{center}
\begin{tabular}{rrrrll}
  \toprule
$j$ & $t_j$ & $n_j$ & $d_j$ & $\hat{S}(t_j)$ & Calculation \\
  \midrule
  0 & 0 & 13 & 0 & $1.000$ & $\frac{13-0}{13}$ \\
  1 & 59 & 13 & 1 & $0.923$ & $\hat{S}(t_0) \left(\frac{13-1}{13}\right)$ \\
  2 & 115 & 12 & 1 & $0.846$ & $\hat{S}(t_1) \left(\frac{12-1}{12}\right)$ \\[2mm]
  3 & 156 & \\[2mm] % 11 & 1 & $0.769$ & $\hat{S}(t_2) \left(\frac{11-1}{11}\right)$ \\
  4 & 268 & \\[2mm] % 10 & 1 & $0.692$ & $\hat{S}(t_3) \left(\frac{10-1}{10}\right)$ \\
  5 & 329 & 9 & 1 & $0.615$ & $\hat{S}(t_4) \left(\frac{9-1}{9}\right)$ \\
  6 & 431 & 8 & 1 & $0.538$ & $\hat{S}(t_5) \left(\frac{8-1}{8}\right)$ \\
  7 & 448 & 7 & 0 & $0.538$ & $\hat{S}(t_6) \left(\frac{7-0}{7}\right)$ \\
  8 & 477 & 6 & 0 & $0.538$ & $\hat{S}(t_7) \left(\frac{6-0}{6}\right)$\\
  9 & 638 & 5 & 1 & $0.431$ & $\hat{S}(t_8) \left(\frac{5-1}{5}\right)$\\[2mm]
  10 & 803 & 4 & 0 & \\[2mm] % $0.431$ & $\hat{S}(t_9) \left(\frac{4-0}{4}\right)$ \\
  11 & 855 & 3 & 0 & \\[2mm] % $0.431$ & $\hat{S}(t_10) \left(\frac{3-0}{3}\right)$ \\
  12 & 1040 & 2 & 0 & \\[2mm] % $0.431$ & $\hat{S}(t_11) \left(\frac{2-0}{2}\right)$ \\
  13 & 1106 & 1 & 0 & \\[2mm] % $0.431$ & $\hat{S}(t_12) \left(\frac{1-0}{1}\right)$ \\
  \bottomrule
\end{tabular}
\end{center}
}
\end{question}

\begin{question}{}
Based solely on the Kaplan-Meier curves for the two treatment groups, which treatment appears to prolong survival more effectively?
\end{question}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{Assumptions of the Kaplan-Meier Estimator}

The Kaplan-Meier estimator makes three important assumptions:
\begin{enumerate}
\item The probability of censoring is unrelated to the outcome of interest.
\item The survival probabilities are the same for participants recruited at different times during the study (e.g., circumstances that could alter the survival, such as treatments, do not change over calendar time).
\item The events occurred at exactly the times specified.
\end{enumerate}

\begin{question}{}
What is one way each of these assumptions could be violated?
\end{question}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{Comparing Kaplan-Meier Curves}

Of course, now the question arises: How do we formally compare two Kaplan-Meier curves? There is a nonparametric hypothesis test for comparing Kaplan-Meier curves called the log-rank test; we will see it in Chapter~\ref{chapter:hypothesisii}. There is also an entire family of linear models, called Cox proportional hazards models, that use the Kaplan-Meier curve as their backbone and model the effects of different covariates on this curve. We will see them in Chapter~\ref{chapter:cox}.
\vspace{5mm}

\begin{question}{}
Here are the data for treatment group $2$ of the \texttt{ovarian} dataset. Perform the calculations of $\hat{S}(t_j)$ for $j = 0, \dots, 13$, starting with $t_0 = 0$. Draw the Kaplan-Meier curve, adding symbols for the censoring events.
{\small
\begin{center}
\begin{tabular}{rlrr}
  \toprule
 & rx & futime & fustat \\
  \midrule
  1 & 2 & 353 & 1 \\
  2 & 2 & 365 & 1 \\
  3 & 2 & 377 & 0 \\
  4 & 2 & 421 & 0 \\
  5 & 2 & 464 & 1 \\
  6 & 2 & 475 & 1 \\
  7 & 2 & 563 & 1 \\
  8 & 2 & 744 & 0 \\
  9 & 2 & 769 & 0 \\
  10 & 2 & 770 & 0 \\
  11 & 2 & 1129 & 0 \\
  12 & 2 & 1206 & 0 \\
  13 & 2 & 1227 & 0 \\
  \bottomrule
\end{tabular}
\end{center}
}
\begin{center}
\includegraphics[width=\textwidth]{img/km-curve-sample-rx2.png}
\end{center}
\end{question}


\documentclass[12pt]{article}
\input{physics1}
\begin{document}

\section*{NYU Physics I---Problem Set 8}

Due Thursday 2018 November 01 at the beginning of lecture.

\paragraph{Problem~\theproblem:}\refstepcounter{problem}%
You walk at a stride rate that is set, in part, by the natural period of
oscillation of your leg, treated as a pendulum.  Estimate this
period by treating your leg as a massless rod with its entire mass in a point mass at
the end. That is an absurd approximation! But it is okay at the order-of-magnitude
level. Or is it: Is your answer reasonable?

\paragraph{Problem~\theproblem:}\refstepcounter{problem}%
A very thin ladder of length $L$ and mass $M$ leans against a vertical
wall, on a horizontal floor, making an angle of $\theta$ with respect
to the wall.  Imagine that there is a large coefficient of friction
$\mu$ at the floor so that the ladder is in static
equilibrium, but assume that the wall is effectively frictionless.

\textsl{(a)} Draw a free-body diagram for the ladder, showing all
forces acting.

\textsl{(b)} Using the bottom of the ladder as the axis of rotation or
origin, compute all the forces and torques on the ladder such that it
is in equilibrium.

\textsl{(c)} Why did I make the wall ``effectively frictionless''?

\textsl{(d)} Re-solve the problem using the \emph{top} of the ladder
as the axis of rotation or origin.  What is different in the end?

\textsl{(e)} At what angles $\theta$ would the ladder start to slip?
If $\mu=0.8$ (not unreasonable for a ladder with hard rubber feet on a wood
floor), what is the maximum angle at which you could lean the ladder?

\paragraph{Problem~\theproblem:}\refstepcounter{problem}%
A long, thin rod of length $L$ and cross-sectional area $A$ and
elastic (Young's) modulus $E$ has mass $M$.

\textsl{(a)} Think of the rod as being like a Hooke's Law spring; it
can be stretched by applying a force.  What is the spring constant $k$
for this spring?

\textsl{(b)} By dimensional analysis, can you combine $L$, $A$, $E$,
and $M$ into a frequency $\omega$?  Do you have more than one choice?  If so,
which of the choices makes most sense? That is, think about how your
answer should scale with changes to the problem.

\paragraph{\problemname~\theproblem:}\refstepcounter{problem}%
In lecture, you saw something like the damped harmonic oscillator
differential equation
\begin{equation}
m\,\frac{\dd^2 x}{\dd t^2} + c\,\frac{\dd x}{\dd t} + k\,x = 0 \quad ,
\end{equation}
where $m$ is the mass, $c$ is a damping coefficient, and $k$ is a
restoring constant (a spring constant).  Here we are going to show
that
\begin{equation}
x(t) = A\,\e^{-\frac{\gamma}{2}\,t}\,\cos (\omega\,t + \phi)
\end{equation}
can be a solution to the differential equation.

\textsl{(a)} What are the units of $c$, $A$, $\gamma$, and $\phi$?

\textsl{(b)} Take a derivative of $x(t)$ to get $v(t)$. Take another
to get $a(t)$.

\textsl{(c)} Now plug your derivatives into the differential equation,
and see if there is a setting of the parameters $\gamma$ and $\omega$
such that the differential equation can be satisfied? \emph{Hint:}
Group sine and cosine terms separately; both sets of terms must sum to
zero for the differential equation to be satisfied. This is related to
the concept of \emph{detailed balance}.

\textsl{(d)} Did you have to assume things about $m, c, k$ to make
your answer work? What things?

\paragraph{Extra Problem (will not be graded for credit):}%
Re-do the previous problem using complex exponentials. That is, assume
\begin{equation}
x(t) = Z\,\e^{\alpha\,t}
\end{equation}
where $Z$ and $\alpha$ are complex numbers. What's different, and
what's the same?

\paragraph{Extra Problem (will not be graded for credit):}%
Show that these two descriptions of a simple harmonic oscillator
\begin{equation}
x(t) = A\,\cos(\omega_0\,t) + B\,\sin(\omega_0\,t)
\end{equation}
\begin{equation}
x(t) = X\,\cos (\omega_0\,t+\phi)
\end{equation}
are completely equivalent by finding the relationship between $A, B$
and $X, \phi$ that makes them identical.

\end{document}


\vsssub
\subsubsection{~$S_{in} + S_{ds}$: Rogers et al. 2012 \& Zieger et al. 2015} \label{sec:ST6}
\vsssub

\opthead{ST6}{AUSWEX, Lake George}{A. Babanin, I. Young, M. Donelan, E. Rogers, S. Zieger, Q. Liu}

\noindent
This version implements observation-based physics for deep-water source/sink terms. These include wind input
source term, and sink terms due to negative wind input, whitecapping
dissipation and wave-turbulence interactions (swell dissipation).
The wind input and whitecapping dissipation source terms are based on
measurements taken at Lake George, Australia; wave-turbulence dissipation
on laboratory experiments and field observations of swell decay; negative
input on laboratory testing. Constraint is imposed on the total wind
energy input through the wind stress, known independently.

\paragraph{Wind input.} Apart from first direct field measurements
of the wind input under strong wind forcing,  the Lake George experiment
revealed a number of new physical features for wind-wave exchange,
previously not accounted for:
(i) full air-flow separation that leads to a relative reduction of
wind input for conditions of strong winds/steep waves;
(ii) dependence of the wave growth rate on wave steepness,
which signifies nonlinear behavior of the wind-input source function;
(iii) enhancement of input in the presence of wave breaking
\citep{art:Dea06,art:Bea07} (the last feature was not implemented in here).
Following \citet{art:RBW12}, this input source term is formulated as
\begin{eqnarray}
\cS_{in}(k,\theta) & = & \frac{\rho_a}{\rho_w}\, \sigma\,\gamma(k,\theta)\,N(k,\theta)  ,
\label{eq:ST601} \\ \gamma(k,\theta) &=& G\,\sqrt{B_n}\,W  ,
\label{eq:ST602} \\
G                &=& 2.8-\Bigl (1+\tanh (10\sqrt{B_n}W-11) \Bigr)  ,
\label{eq:ST603} \\
B_n              &=& A(k)\,N(k)\sigma\,k^3  ,
\label{eq:ST604} \\
W                &=& \left (\frac{U_s}{c}\,-\,1 \right )^2  .
\label{eq:ST605}
\end{eqnarray}

\noindent
In (\ref{eq:ST601})$-$(\ref{eq:ST605}) $\rho_a$ and $\rho_w$ are densities
of air and water, respectively, $U_s$ is the scaling wind speed, $c$ refers to
wave phase speed, $\sigma$ is radian frequency and $k$
is wavenumber. The spectral saturation (\ref{eq:ST604}), introduced
by \citet{art:Phi84}, is a spectral measure of steepness $ak$.  The
omni-directional action density is obtained by integration over all directions:
$N(k)=\int N(k,\theta)d\theta$.\linebreak
The inverse of the directional spectral narrowness $A(k)$ is defined as\linebreak
$A^{-1}(k) =$ $\int_{0}^{2\pi} [{N(k,\theta)}/{N_{\max}(k)}] d\theta$,
where $N_{\max}(k)=\max\bigl \{N(k,\theta)\bigr \}$, for all
directions $\theta\in[0,2\pi]$ \citep{art:BS87}.

\citet{art:Dea06} parameterized the growth rate (\ref{eq:ST602}) in terms
of winds 10\,m above the mean surface. Wave models, however, typically employ friction
velocity $u_\star=\tau/\rho_a$ to assure a consistent fetch law across
different wind speeds \citep[][p. 253]{bk:WAM94}. Therefore, \citet{art:RBW12}
advocated using an approximation
\begin{equation}
U_s = U_{10} \simeq \Upsilon u_{\ast},\ \mathrm{and}\ \Upsilon = 28
\label{eq:Upsilon}
\end{equation}
by following \citet{art:KHH84}.

\begin{eqnarray}
W_1 & = & \mathrm{max}^2 \left \{ 0,\frac{U}{c}\ \cos(\theta-\theta_w)-1
\right \}  , \label{eq:ST606-1} \\
W_2 & = & \mathrm{min}^2 \left \{ 0,\frac{U}{c}\ \cos(\theta-\theta_w)-1
\right \} .\label{eq:ST606-2}
\end{eqnarray}

\noindent
The directional distribution of $W$ is implemented as the sum of favorable
winds (\ref{eq:ST606-1}) and adverse winds (\ref{eq:ST606-2}), so that they
complement one another (i.e. $W=\{W_1\cup W_2$\}, see {\it Negative Input}
later this section):
\begin{equation}\label{eq:ST606}
W=W_1-a_0\,W_2  .
\end{equation}

\paragraph{Wind input constraint.} One important part of the input is the
calculation of the momentum flux from the atmosphere to the ocean,
which must agree with the flux received by the waves. At the surface,
the stress $\vec{\tau}$ can be written as the sum of the viscous and
wave-supported stress: $\vec{\tau} = \vec{\tau}_{v} + \vec{\tau}_{w}$.
The wave-supported stress $ \vec{\tau}_{w}$ is used as the principal
constraint for the wind input and cannot exceed the total stress
$\vec{\tau} \le \vec{\tau}_{tot}$.  Here the total stress is determined
by the flux parameterization: $\vec{\tau}_{tot}=\rho_a u_\star|u_\star|$.
The wave-supported stress $\tau_w$ can be calculated by integration over
the wind-momentum-input function:

\begin{equation}\label{eq:ST609}
   \vec{\tau}_w = \rho_w g \int_{0}^{2\pi} \int_{0}^{k_{max}}
   \frac{S_{in}(k^\prime,\theta)}{c} \Bigl (\cos\theta,\sin\theta \Bigr )
   dk^\prime d\theta  .
\end{equation}

\noindent
Computation of the wave-supported stress (\ref{eq:ST609}) includes the
resolved part of the spectrum up to the highest discrete wavenumber $k_{max}$,
as well as the stress supported by short waves. To account for the latter,
an $f^{-5}$ diagnostic tail is assumed beyond the highest frequency in the
energy density spectrum. In order to satisfy the constraint and in the case
of $\vec{\tau} > \vec{\tau}_{tot}$, a wavenumber dependent factor $L$ is
applied to reduce energy from the high frequency part of the spectrum:
$S_{in}(k^\prime)=L(k^\prime)\,S_{in}(k^\prime)$ with

\begin{equation}\label{eq:ST610}
L(k^\prime) = \min \Bigl \{ 1, \exp \bigl ( \mu\,[1- U/c] \bigr ) \Bigr
\}  .
\end{equation}

\noindent
The reduction (\ref{eq:ST610}) is a function of wind speed and phase speed and
follows an exponential form designed to reduce energy from the discrete part
of the spectrum. The strength of reduction is controlled by coefficient $\mu$,
which has a greater impact at high frequencies and only little impact on the
energy-dominant part of the spectrum. The value of $\mu$ is dynamically
calculated by iteration at each integration time step \citep{art:Tea10}.

The drag coefficient is given by
\begin{equation}\label{eq:ST607}
C_d \times 10^4 = 8.058 + 0.967 U_{10} - 0.016 U_{10}^2 ,
\end{equation}
which was selected and
implemented as switch {\code FLX4}. The parameterization was proposed by
\citet{art:Hwa11} and accounts for saturation, and further decline
for extreme winds, of the sea drag at wind speeds in excess of 30\,m~s$^{-1}$.
To prevent $u_\star$ from dropping to zero at very strong winds
($U_{10}\ge50.33$m~s$^{-1}$) expression (\ref{eq:ST607}) was modified to yield
$u_\star=2.026$m~s $^{-1}$. {\it Important!} In {\code ST6}, bulk adjustment to any
uniform bias in the wind input field is done in terms of the wind stress
parameter $u_\star$ rather than $U_{10}$. In order to achieve that, the
factor in expression $C_d \times 10^4$ on the left hand side of
(\ref{eq:ST607}) was substituted with $C_d \times \mathrm{FAC}$ and added
as the {\F FLX4} namelist parameter {\code CDFAC} (see {\it Bulk Adjustment}
at the end of this section).
The viscous drag coefficient,
\begin{equation}\label{eq:ST608}
  C_v \times 10^3 = 1.1 - 0.05 U_{10} ,
\end{equation}
was parameterized by \citet{art:Tea10} as a function of wind speed using
data from \citet{art:BP98}.

\paragraph{Negative Input.} Apart from the positive input, {\code ST6} also has a
negative input term in order to attenuate the growth of waves in those parts
of the wave spectrum where an adverse component of the wind stress is present
(\ref{eq:ST606-1}--\ref{eq:ST606-2}). The growth rate for adverse winds
is negative \citep{pro:Don99} and is applied after the constraint of
the wave-supported stress $\tau_w$ is met. The value of $a_0$
(in \ref{eq:ST606}) is a tuning parameter in the parameterization of the
input and is adjustable through the {\F SIN6} namelist parameter {\code  SINA0}.

\noindent
\paragraph{Whitecapping Dissipation.} For dissipation due to wave breaking,
the Lake George field study revealed a number of new features: (i) the
threshold behavior of wave breaking \citep{art:BBY01}. The waves do not
break unless they exceed a generic steepness in which case the wave breaking
probability depends on the level of excedence above this threshold steepness.
For waves below the critical threshold, whitecapping dissipation is zero.
(ii) the cumulative dissipative effect due to breaking and dissipation of
short waves affected by longer waves
\citep{pro:Don01,pro:BY05,art:Mea06,art:YB06,art:Bea10},
(iii) nonlinear dissipation function at strong winds
(\citeauthor{art:Mea06}, \citeyear{art:Mea06};\linebreak
 \citeauthor{art:Bea07}, \citeyear{art:Bea07}),
(iv) bimodal distribution of the directional spreading of the dissipation
\citep{art:YB06,art:Bea10} (the last feature was not implemented in {\code ST6}).
Following \citet{art:RBW12}, the whitecapping dissipation term is
implemented as:
\begin{equation}\label{eq:ST620}
  \cS_{ds}(k,\theta) = \Bigl [ T_1(k,\theta) + T_2(k,\theta) \Bigr ]\ N(k,\theta) ,
\end{equation}

\noindent
where $T_1$ is the inherent breaking term, expressed as the traditional function
of the wave spectrum, and $T_2$, expressed as an integral of the wave spectrum below
wavenumber $k$, accounts for the cumulative effect of short-wave breaking or
dissipation due to longer waves at each frequency/wavenumber. The inherent breaking
term $T_1$ is the only breaking-dissipation term if this frequency is at or below
the spectral peak. Once the peak moves below this particular frequency, $T_2$
becomes active and progressively more important as the peak downshifts further.

The threshold spectral density $F_{\mathrm{T}}$ is calculated as
\begin{equation}\label{eq:ST621}
  F_{\mathrm{T}}(k)=\frac{\varepsilon_{\mathrm{T}}}{A(k)\,k^3}  ,
\end{equation}
where $k$ is the wavenumber and with
$\varepsilon_{\mathrm{T}}=0.035^2$ being an empirical constant
\citep{art:Bea07,bk:Bab11}. Let the level of exceedence above the critical
threshold spectral density (at which stage wave breaking is predominant) be
defined as $\Delta(k)=F(k)-F_{\mathrm{T}}(k)$. Furthermore, let
$\mathcal{F}(k)$ be a generic spectral density used for normalization,
then the inherent breaking component can be calculated as
\begin{equation}\label{eq:ST622}
T_1(k)=a_1 A(k)\frac{\sigma}{2\pi} \left [ \frac{\Delta(k)}{\mathcal{F}(k)}
\right ]^{p_1}  .
\end{equation}

\noindent
The cumulative dissipation term is not local in frequency space and is
based on an integral that grows towards higher frequencies, dominating at
smaller scales:

\begin{equation}\label{eq:ST623}
T_2(k)=a_2 \int\limits_0^k A(k) \frac{c_g}{2\pi} \left [
\frac{\Delta(k)}{\mathcal{F}(k)} \right ]^{p_2}\!\!dk .
\end{equation}

\noindent
The dissipation terms (\ref{eq:ST622})$-$(\ref{eq:ST623}) depend on five
parameters: a generic spectral density $\mathcal{F}(k)$ used for
normalization, and four coefficients $a_1$, $a_2$, $p_1$, and $p_2$.  The
coefficients $p_1$ and $p_2$ control the strength of the normalized threshold
spectral density $\Delta(k)/\mathcal{F}(k)$ of the dissipation terms.
Namelist parameter {\code SDSET} changes between the spectral density
$F(k)$ and threshold spectral density $F_{\mathrm{T}}(k)$ for
normalization in (\ref{eq:ST622})--(\ref{eq:ST623}).
According to \citet{art:Bea07} and \citet{art:Bab09}, the directional
narrowness parameter is set to unity $A(k)\approx 1$ in Eqs.
(\ref{eq:ST621})$-$(\ref{eq:ST623}).

% -------------------------------------------------------------------
\begin{table} \begin{center}
\footnotesize
\begin{threeparttable}
\begin{tabular}{|l|c|c|c|c|c|} \hline \hline
Parameter          &  WWATCH var. & namelist &  vers.\,4.18 & vers.\,5.16 & vers.\,\WWver \\
\hline
  $F_{\mathrm{T}}$ &  SDSET       & SDS6     &  T       &  T         & T          \\
  $a_1$            &  SDSA1       & SDS6     & 6.24E-7  & 3.74E-7    & 4.75E-6    \\
  $p_1$            &  SDSP1       & SDS6     &  4       &  4         & 4          \\
  $a_2$            &  SDSA2       & SDS6     & 8.74E-6  & 5.24E-6    & 7.00E-5    \\
  $p_2$            &  SDSP2       & SDS6     &  4       &  4         & 4          \\
\hline
  $\Upsilon$\tnote{\textdagger}       &  SINWS       & SIN6     & n/a      & n/a        & 32.0       \\
  $N_{hf}$\tnote{\textdagger}         &  SINFC       & SIN6     & n/a      & n/a        & 6.0        \\
  $a_0$            &  SINA0       & SIN6     & 0.04     & 0.09       & 0.09       \\
  $b_1$ is constant&  CSTB1       & SWL6     & n/a      &  F         & F          \\
  $b_1$, $B_1$     &  SWLB1       & SWL6     & 0.25E-3  & 0.0032     & 0.0041     \\
  $\mathrm{FAC}$   &  CDFAC       & FLX4     & 1.00E-4  & 1.00E-4    & 1.0        \\
\hline
  $C$              &  NLPROP      & SNL1     & 3.00E7   &  3.00E7    & 3.00E7    \\
 \hline \hline
\end{tabular}
\begin{tablenotes}
	\item[\textdagger] In WW3 version 4.18 and 5.16, $\Upsilon = 28.0$
            and $N_{hf} = 6.0$ were hard-coded in {\code ST6} module.
\end{tablenotes}
\end{threeparttable} \end{center}
\caption{Summary of calibration parameters for {\code ST6} when it is applied with
         the {\code DIA} nonlinear solver (section~\ref{sec:NL1}). Values tabulated represent default model settings.
         Abbreviation ``n/a'' indicates that the variable is not applicable
         in that release of the code.}
\label{tab:ST601} \botline \end{table}
% -------------------------------------------------------------------

\citet{art:RBW12} calibrated the dissipation terms based on duration-limited
academic tests. Calibration coefficients used in {\code ST6} and listed in
Table~\ref{tab:ST601} differ somewhat from those of \citet{art:RBW12}
mainly due to the fact that the wave-supported stress $\vec{\tau}_w$
is implemented in the form of vector components and the non-breaking swell
dissipation (\ref{eq:ST624}) was previously not accounted for in
\citet{art:RBW12}.

\paragraph{Swell Dissipation.} In the absence of wave breaking,
other mechanisms of wave attenuation are present. Here, they are
referred to as swell dissipation and parameterized in terms of
the interaction of waves with oceanic turbulence \citep{bk:Bab11}.
This mechanism, however, remains active for the wind-generated
waves too. Its contribution across the spectrum is small, if the
spectrum is above the wave-breaking threshold, but it is dominant
at the front face of the spectrum, or even at the peak in case of
the full Pierson-Moscowitz development.

\begin{equation}\label{eq:ST624}
  \cS_{swl}(k,\theta) = -\frac{2}{3}b_1 \sigma\ \sqrt{B_n}\ N(k,\theta).
\end{equation}

\noindent
By making coefficient $b_1$ in Eq. (\ref{eq:ST624}) dependent
on steepness the large gradient in the spatial bias in wave height
can be reduced:

\begin{equation}\label{eq:ST625}
   b_1 = B_1 \, 2\sqrt{E}\,k_p .
\end{equation}

In Eq. (\ref{eq:ST625}), $B_1$ is a scaling coefficient,
$E$  is the total sea surface variance Eq. (\ref{eq:etot}) and $k_p$
is the peak wavenumber.  Eq. (\ref{eq:ST625}) can be
flagged through the {\F SWL6} namelist parameter {\code CSTB1}.The value for the
coefficient $B_1$ in Eq. (\ref{eq:ST625}) and/or $b_1$ in Eq. (\ref{eq:ST624})
is customizable through the {\F SWL6} namelist parameter {\code SWLB1}
(see Table~\ref{tab:ST601}).

\noindent
\paragraph{Updates since vers.\,\WWver} Following \citet{art:RBW12}, the
scaling wind speed $U_s = 28u_{\ast}$ (\ref{eq:Upsilon}) were adopted in
vers. 4.18 and vers. 5.16 (Table~\ref{tab:ST601}). Such configurations of {\code ST6} have been proven
skillful for different spatial scales and under different weather
conditions \citep[e.g.][]{art:ZBRY15, liu2017}. \citet[][their Fig. 5]{art:ZBRY15},
however, also suggested {\code ST6} (vers. 4.18 and vers. 5.16) was inclined to
overestimate the energy level of the high-frequency tail of the spectrum,
indicating an inaccurate balance of different source terms in this
specific frequency range.

Rogers (2014, unpublished work) found that using $U_s = 32u_{\ast}$ (i.e.,
$\Upsilon = 32$) could improve model skills in estimating tail level in
the {\code ST6} implementation in SWAN [see also \citet{Rogers2017}]. Following
this, \citet{Liu2019} carried out a thorough recalibration of {\code ST6} with WW3,
and the new set of parameters (i.e., $a_0,\ a_1,\ a_2,\ B_1$) is summarized
in the last column of Table~\ref{tab:ST601}. The updated {\code ST6} package not
only performs well in predicting commonly-used bulk wave parameters (e.g.,
significant wave height and wave period) but also yields a clearly-improved
estimation of high-frequency energy level (in terms of saturation spectrum
and mean square slope). In the duration-limited test, the omnidirectional
frequency spectrum $E(f)$ from the recalibrated {\code ST6} shows a clear transition
behavior from the power law of approximately $f^{-4}$ to the power law of
about $f^{-5}$, comparable to previous field studies \citep{Forristall1981}.

% -------------------------------------------------------------------
\begin{table}[htbp]
	\footnotesize
	\begin{center}
	\begin{tabular}{|l|c|c|c|c|} \hline \hline
            {\code ST6} & $a_0$ & $a_1$ & $a_2$ & $B_1$\\
                        & 0.05 & $4.75 \times 10^{-6}$ & $7.00 \times 10^{-5}$ & $6.00 \times 10^{-3}$  \\
            \hline
            {\code GMD} & $\lambda$ & $\mu$ & $\theta_{12}\ (^{\circ})$ & $C_{deep}$  \\
                        & $0.127$ & $0.000$ & $\ 3.0$ & $4.88 \times 10^7$            \\
		        & $0.127$ & $0.097$ & $21.0$ & $1.26 \times 10^8$             \\
		        & $0.233$ & $0.098$ & $26.5$ & $6.20 \times 10^7$             \\
		        & $0.283$ & $0.237$ & $24.7$ & $2.83 \times 10^7$             \\
		        & $0.355$ & $0.183$ & $-$ & $1.17 \times 10^7$                \\
            \hline \hline
	\end{tabular}
	\end{center}
        \caption{Summary of calibration parameters for {\code ST6} when it is applied with the {\code GMD} nonlinear solver (or specifically, {\code G35})}
	\label{tab:ST602}
	\botline
\end{table}
% -------------------------------------------------------------------

Apart from applying {\code ST6} with the {\code DIA} (section~\ref{sec:NL1}) nonlinear solver, \citet{Liu2019}
also made an attempt to run {\code ST6} with the {\code GMD} parameterization of $S_{nl}$
(section~\ref{sec:NL3}). As a first step, only the {\code GMD} configuration with
5 quadruplets and a three-parameter quadruplet definition
\citep[i.e., {\code G35} in][]{tol:OMOD13d} was adopted. The tunable parameters
of the {\code GMD} which were specifically optimized for {\code ST6} by using the holistic
genetic optimization technique designed by \citet{tol:OMOD13e}, and the
corresponding tunable parameters of {\code ST6} are summarized in
Table~\ref{tab:ST602}\footnote{For the fifth quadruplet layout of {\code GMD} shown
in Table~\ref{tab:ST602}, the three-parameter $(\lambda,\ \mu,\ \theta_{12})$
quadruplet definition degrades to a two-parameter $(\lambda,\ \mu)$ form, and
$\theta_{12}$ is implied by the value of $\mu$ \citep{tol:OMOD13d}. Accordingly,
a combination of {\code ST6+GMD} and the conservative nonlinear high-frequency
filter of \citet{tol:OMOD11} [see also section~\ref{sec:NLS}] might be
necessary to stabilize the model integration, particularly for high-resolution
spectral grid (say, $\Delta \theta < 5^{\circ}$).},\footnote{Unlike
Table~\ref{tab:ST601}, here we only show important parameters of {\code ST6} and
{\code GMD}. The reader is refered to {\code bin/README.UoM} for the detailed
set up of namelist variables for this specific model configuration.}.
\citet{Liu2019} demonstrated that in the duration-limited test, the
{\code GMD}-simulated $E(f)$ is in excellent agreement with that from the exact
 solutions of $S_{nl}$(e.g., {\code WRT}; section~\ref{sec:NL2}) \citep[see also][]{tol:OMOD13d}]. In a 1-yr global
hindcast, the {\code DIA}-based model overestimates the low-frequency wave energy
(wave period $T > 16$ s) by 90\%. Such model errors are reduced significantly
by the {\code GMD} to $\sim$20\%. It is noteworthy that the computational expense
of the {\code GMD} approach presented in Table~\ref{tab:ST602}, however, is about
5 times larger than that of the {\code DIA}.

To flexibly control the high-frequency extent of the prognostic frequency
region, we introduced
\begin{equation}
f_{hf} = N_{hf}/T_{m0, -1}
\end{equation}
in vers.\,\WWver, where $f_{hf}$ is the cut-off high-frequency limit
(\ref{eq:tail_E_f}), $T_{m0,-1}$ is the mean wave period defined in
(\ref{eq:Tm0m1}). $N_{hf}$ is set through a namelist parameter SINFC
(Table~\ref{tab:ST601}), and a negative $N_{hf}$ (say, $N_{hf} = -1$)
means \emph{the high-frequency spectral tail evolves freely without any
prescribed slope.}

\noindent
\paragraph{Dominant Wave Breaking Probability}
Following \citet[][their Fig.~12]{art:BBY01}, the dominant wave breaking probability $b_T$ can be estimated from the wave spectrum $F(f, \theta)$ according to the following parametric form
\begin{equation}
b_T = 85.1 \Big[ (\epsilon_p - 0.055) (1 + H_s / d) \Big]^{2.33},
\label{eq:bt}
\end{equation}
where $H_s$ is the significant wave height, $d$ is the water depth, $\epsilon_p$ is the significant steepness of the spectral peak, given by
\begin{equation}
%\left \lbrace
\begin{array}{rcl}
\epsilon_p &=& H_p k_p / 2\\
H_p &=& 4 \Big[\int_{0}^{2\pi} \int_{0.7f_p}^{1.3f_p} F(f, \theta) \mathrm{d}f \mathrm{d}\theta \Big]^{1/2}
\label{eq:steepness}
\end{array}
%\right.
\end{equation}
where $k_p$ and $f_p$ are the peak wavenumber and frequency, respectively. Note that only the contribution from wind seas is considered when we calculate $H_s$, $H_p$ and $f_p$ ($k_p$) from $F(f, \theta)$ (Eqs. \ref{eq:bt} and \ref{eq:steepness}). Following \citet{Janssen1989} and \citet{Bidlot2001}, we consider spectral components as wind seas when
\begin{equation}
\frac{c(k)}{U_{10} \cos (\theta - \theta_u)}  < \beta_w,
\label{eq:beta}
\end{equation}
where $c(k)$ is the phase velocity, $U_{10}$ is the wind speed at 10 m above the sea surface, $\theta_u$ is the wind direction and $\beta_w$ is the constant wind forcing parameter. We implemented $\beta_w$ as a tunable parameter (the {\F MISC} namelist parameter {\code BTBET}), and used $\beta_w=1.2$ by default.

\noindent
\paragraph{Bulk Adjustments.} The source term
{\code ST6} has been calibrated with flux parameterization {\code FLX4}.
Bulk adjustment to the wind filed can be achieved by re-scaling the drag
parameterization {\code FLX4} through the {\F FLX4} namelist parameter {\code
 CDFAC=1.0E-4}\footnote{This was changed to {\code CDFAC=1.0} since vers.\,\WWver\ as the magnitude $10^{-4}$ was hard-coded
in {\code FLX4} module. (Table~\ref{tab:ST601})}. This has a similar effect to tuning variable
$\beta_{max}$ in {\code ST4} source term package, equations
(\ref{eq:SinWAM4}) and (\ref{eq:tauhfint}), which is customizable
through namelist parameter {\code BETAMAX} (see section
\ref{sec:ST3}--\ref{sec:ST4}). \citet{pro:Aea11} and \citet{art:RA13}
listed different sets of values that allow us to adjust to different
wind fields. When optimizing the wave model, it is recommended to
only re-tune parameters $a_0$, $b_1$ and $\mathrm{FAC}$. Again, $\mathrm{FAC}$
can potentially eliminate a bias in the wind field, which typically changes
with the selection of the reanalysis product. This reduction was tested
for extreme wind conditions such as hurricanes \citep{art:ZBRY15}.  In
a global hindcast, the coefficient for the negative input can be used to tune
the bulk of the wave heights in scatter comparisons, whereas the scaling
coefficient for swell dissipation primarily affects large sea states.
When the discrete interaction approximation ({\code DIA}) is used to compute the four-wave
interaction, the default value for the proportionality constant changes to
$C=3.00\times10^7$.

\textrm{\textit{\underline{Limitations of the code:}}} For vers. 4.18 and
vers. 5.16, in cases where the minimum time step for the dynamical source term
integration is much smaller than the overall time step (i.e. less than
1/15th), the model becomes unstable. The issue has been solved since vers.\,\WWver.


%add
\section{Hydraulic structures}
\label{sec-structures}
The term {\em hydraulic structures} refers to control structures such as tidally-operated gates,
barriers, weirs and culverts as well as to coupled boundary conditions
representing direct transfers of water from an outflow to an inflow boundary due to mechanisms like low head pumps.
There are numerous gates and control structures in the San Francisco Bay-Delta. Here we describe the way structures are modeled and the formulas used to calculate flow through them.

Hydraulic structures are represented in SCHISM as paired boundary condition (Figure \ref{fig:structmesh}). Flow is calculated based on head differences at two {\em reference nodes}, one on the nominal upstream and downstream sides of the structure (but not necessarily adjoining the structure). Once the flow is calculated, it is disaggregated as a homogenous flux boundary condition over the breadth of the structure. The boundaries are enforced using a relaxation formulation, which provides some natural ramping of flow when gates that are suddenly opened or closed. Transport is coupled between the side that is an outflow and the side that is an inflow.

\begin{figure}
	\centering
		\includegraphics[scale=1]{image/struct}
	\caption{Hydraulic structure definition imposed on horizontal grid.}
	\label{fig:structmesh}
\end{figure}

A number of pre-defined flow structures are already in place covering all the cases we encountered in the Bay-Delta; with a little programming the system can easily be expanded to accommodate new structures.
The structures we have already implemented are listed below. All of the structures admit control of key (indicated) parameters using time series.

Structures can also be removed in SCHISM by adding
an appropriate entry in a time series. When a structure is removed, the region between the paired boundaries reverts to the ordinary equations of motion -- ie, it is if the structure did not exist.

\subsection{Flow transfers}
\label{sec-transfer}
A flow transfer is a simple coupled boundary condition wherein a fixed flow $Q_s$ is stipulated. This flow
is imposed as an outflow boundary on one the paired boundaries and and inflow on the other. Constituent mass
is conserved.

\begin{figure}
	\centering
		\includegraphics[scale=1]{image/weir}
	\caption{Free flowing (a) and submerged (b) weir flow cases.}
	\label{fig:weir}
\end{figure}

\subsection{Weirs}
A weir may be dry, submerged or free flowing (see Figure \ref{fig:weir}) depending on the position of the upstream
and downstream water surfaces $z_{u}$, $z_{d}$ compared to the weir invert elevation $z_{inv}$. Note that in the formulas
below,

For the free flowing case:
$$
Q_s^f=\sgn{(z_{u} - z_{d})} C_{op} C_{f} A \sqrt{2g H}
$$
where
\begin{align*}
&Q_s^f  &\text{free flow flow through structure (cms)} &\\
&\sgn        &\text{sign function (to induce up/downstream directionality)}  &\\
&z_u         &\text{upstream reference elevation  (m)}  &\\
&z_d         &\text{downstream reference elevation (m)}  &\\
&z_{inv}     &\text{invert elevation of the weir (m)}  &\\
&H = \max(z_u,z_d) - z_{inv}  &\text{is the energy head above the weir} &\\
&A                            &\text{area of flow (m\textsuperscript{2}) }&\\
&C_op               &\text{(directionally varying) operating coefficient (unitless)} &\\
&C_f                &\text{flow/gate coefficient (unitless)}  &\\
&g                  & \text{gravity (m/s\textsuperscript{2})} & \\
\end{align*}
For commentary on coefficients, see \cite{Rantz82}. Note that in the formulation above, the $\sqrt{2g}$
term has been kept separate and the area calculation uses water surface height.
Furthermore, note that $z_u$ and $z_d$ are pre-assigned upstream and downstream orientations,
whereas $H$ is the energy head in the direction that is upstream of the weir in terms of actual flow.

The submerged case is derived from the free flowing case using the correction given by \citet{Villemonte47}:
\begin{align*}
Q_s^s = Q_s^f(1 - S^{1.5})^{0.385} \\
S = \frac{\min(z_u,z_d) - z_{inv}}{\max(z_u,z_d) - z_{inv}}
\end{align*}
in terms of the {\em submergence ratio} $S$.

If both sides are dry, of course $Q_s=0$ for the structure. Note that this refers to being dry with respect to the invert elevation.
The nodes may not go dry in the ordinary sense with respect to the bed -- this is the same restriction as at other SCHISM boundaries.

\subsection{Radial gates}
\label{sec:radial}
A radial gate is parametrized as shown in Figure \ref{fig:radial}, although at the moment we have ignored the kinetic
energy component of upstream head (so that $H_1 = y_1$). For the case where the radial gate is completely out
of the water or the tailwater elevation is not sufficiently high to affect the upstream (submergence ratio described in the previous
section is less than $S_p=0.66$),
the gate reverts to a modified weir equation described momentarily. For the case where the radial gate is completely submerged
(submergence ratio greater than $S_f=0.80$),
the gate is treated as an orifice as given in Section \ref{sec-orifice}.

            %diff = max_elev - min_elev
            %coef_matching_factor = sqrt(1.d0/(1.d0-PART_SUBMERGE))
            %flow = signed_coef*area*sqrt2g*sqrt(diff)
            %! now weigh the two so that the flow makes a linear transition
            %subfrac = (submerge_ratio-PART_SUBMERGE)/(FULL_SUBMERGE - PART_SUBMERGE)
            %flow = ((1.d0 - subfrac)*coef_matching_factor + subfrac)*flow
For free flow:
$$
Q_s^f = \sgn{(z_{u} - z_{d})} C_{op} C_{f} A \sqrt{2g H}
$$
and for partially submerged flow ($S_p < S \le S_f$):
$$
Q_s^p = \sgn{(z_{u} - z_{d})} C_{op} C_{f} A \sqrt{2g \left|\D z\right|}[(1-\hat{S})m+\hat{S}]
$$
where
\begin{align*}
&\hat{S}=\frac{S-S_p}{S_f-S_p} & \text{is the submergence fraction} \\
&m = \sqrt{\frac{1}{1-S_p}} & \text{is a coefficient matching factor to create a smooth transition}. \\
\end{align*}

For fully submerged flow $S>S_f$, the orifice equation is used. This is equivalent to the submerged equation with
$\hat{S}=1$.

\begin{figure}
	\centering
		\includegraphics[scale=1]{image/radial_gate}
	\caption{Radial gate.}
	\label{fig:radial}
\end{figure}

\subsection{Radial gates with linear coefficient}
This is an alternative radial gate formula modified from a suggestion by Tony Wahl of the USBR (personal communication)
that was incorporated because it matches Clifton Court well.
The rating formula is a little simpler, but the flow coefficient is a linear function of gate height:

$$
Q_s = \sgn{(z_{u} - z_{d})} C_{op} C_{f} A \sqrt{2g \left|\D z\right|}
$$
where
$$C_f = d + sR$$
is the gate coefficient linearly dependent on the ratio of gate opening to upstream head:
$$R = \min(\frac{H_{gate}}{H_1},1.0)$$
with constant and linear parameters $d$ and $s$ respectively.
Some special cases surround the term $A$, given that the top of the radial gate
may be dry or submerged.

\subsection{Orifice}
\label{sec-orifice}
The orifice option is used to model a sluice gate or flashboard or other devices that
presents a (rectangular) apertures to flow. Flow in this case is given by:

$$
Q_{s} = \sgn{(z_{u} - z_{d})} C_{op} C_{f} A \sqrt{2g \left|\D z \right|}
$$

Some special cases surround the term $A$, given that the orifice may be dry, partially submerged or completely
submerged. Typically, the orifice equation is most useful when flow is fully submerged.

\subsection{Culverts}
A culvert is currently modeled as a circular orifice. In other words, it is the same as the orifice case
but with a different formula for $A$. This treatment neglects some of the nuances of head and tailwater control
as described by \cite{Bodhaine68}


\section{Empirical analysis}
    \begin{frame}{Empirical analysis}
In previous sections, the series were shown in levels and individually. The variables in their logarithmic transformations are shown below:\par
As observed in the previous series, their seasonality is highlighted and with the help of dichotomous variables, the impact of this problem is reduced. The seasonally adjusted
series are shown below:\par
In these series, the Unit Root test was applied using the Dickey-Fuller method, in which the hypotheses are as follows:\par
\begin{center}
\textbf{H0} = Has unit root.
\textbf{HA} = The series is stationary.
\end{center}
In the first place, the test was applied to Remittances, the results obtained \textbf{(-1.446)} refer to the fact that the test adding the trend is not rejected H0 \textbf{(-4.051 at 1 percent, -3.455 at 5 percent and -3.153 at 10 percent)} and the form of change in levels \textbf{(-1.826)} is not rejected H0 \textbf{(-2.367 at 1 percent, -1.661 at 5 percent and -1.291 at 10 percent)}. \par
Second, the test was applied to Mexico's GDP where the results \textbf{(-3.656 in trend and -1,349 in change in levels)} do not reject H0 in its 1 percent trend form \textbf{(-4.051 at 1 percent, -3.455 at 5 percent and -3.153 at 10 percent)} and its change in levels at 5 percent \textbf{(-2.367 at 1percent, -1.661 at 5 percent and -1.291 at 10 percent)}.\par
Third, the test was applied to the United States GDP where the results \textbf{(-2.914 in trend and -1.164 in change in levels)} do not reject H0 in its trending form \textbf{(-4.051 at 1 percent, -3.455 at 5 percent and -3.153 at 10 percent)} and in its change in levels \textbf{(-2.367 at 1 percent, -1.661 at 5 percent and -1.291 at 10 percent)}.\par
Finally, the test was performed at the Real Exchange Rate where the results \textbf{(-3.492 in trend and -2.701 in change in levels)} do not reject H0 in its form with a trend of 1 percent \textbf{(-4.051 at 1 percent, -3.455 at 5 percent and -3.153 at 10 percent)} and in its change in levels if it rejects H0 \textbf{(-2.367 at 1 percent, -1.661 at 5 percent and -1.291 at 10 percent)}.\par
Since the series has structural changes, the Zivot and Andrews test is carried out considering the same hypotheses as the previous test. For Remittances in the first instance, the results for the form with change in the intercept and trend \textbf{(-4.783)} are not rejected H0 \textbf{(-5.57 at 1 percent, -5.08 at 5 percent and -4.82 at 10 percent)} and in the same way , in the way of minimizing lags \textbf{(-3.208)}, H0 is not rejected \textbf{(-5.34 at 1 percent, -4.80 at 5 percent and -4.58 at 10 percent)}.\par
Second, the test was performed on the Mexican GDP series where the results \textbf{(-4.250)} show that the test does not reject H0 with the change in the intercept and trend \textbf{(-5.57 at 1 percent, -5.08 at 5 percent and -4.82 at 10 percent)}, in the same way \textbf{(-4.689)} H0 at 5 percent is not rejected in its way of minimizing lags \textbf{(-5.34 at 1 percent, -4.80 at 5 percent and -4.58 at 10 percent)}.\par
Third, the test was performed on the US GDP series where the results \textbf{(-4.856)} show that the test does not reject H0 with the change in the intercept and trend to 5 percent \textbf{(-5.57 to 1 percent, -5.08 at 5 percent and -4.82 at 10 percent)}, but if it rejects \textbf{(-6.059)} H0 in its way of minimizing lags \textbf{(-5.34 at 1 percent, -4.80 at 5 percent and -4.58 at 10 percent)}.\par
Finally, the test was carried out on the Real Exchange Rate series where the results \textbf{(-4.003)} show that the test does not reject H0 with the change in the intercept and trend \textbf{(-5.57 at 1 percent, -5.08 at 5 percent and -4.82 at 10 percent)}, in the same way \textbf{(-3.672)} H0 is not rejected in its way of minimizing lags \textbf{(-5.34 at 1 percent, -4.80 at 5 percent and -4.58 at 10 percent)}.\par
In conclusion, it can be seen that the previous series in their seasonally adjusted form are non-stationary because they do not reject H0 in most cases. So we proceed to analyze the growth of each variable by differentiating them. The series in first differences are shown below:\par
Similarly, in each of the series, the Unit Root test was applied using the Dickey-Fuller and Zivot and Andrews method, however, the trend is not taken into account since it is not observed in the previous graphs, the hypotheses are the following:\par
\begin{center}
\textbf{H0} = Has unit root.\par
\textbf{HA} = The series is stationary.
\end{center}
In the first place, the series of Remittances in first differences shows in the results \textbf{(-11.851 in the DF test and -5.274 in the ZA test)} that reject H0 in both tests \textbf{(-3.518 at 1 percent, -2.895 at 5 percent and - 2.582 at 10 percent in DF and -5.34 percent at 1 percent, -4.80 at 5 percent and -4.58 at 10 percent in ZA)} affirming that said integrated series of order I is stationary.\par
Secondly, the series of the Gross Domestic Product of Mexico in first differences shows in the results \textbf{(-23.585 in the DF test and -4.698 in the ZA test)} that rejects H0 in both tests \textbf{(-3.518 at 1 percent, -2.895 at 5 percent and -2.582 at 10 percent in DF and -5.34 percent at 1 percent, -4.80 at 5 percent and -4.58 at 10 percent in ZA)} affirming that said integrated series of order I is stationary.\par
Third, the series of the Gross Domestic Product of the United States in first differences shows in the results \textbf{(-5.997 in the DF test and -6,914 in the ZA test)} that reject H0 in both tests \textbf{(-3.518 at 1 percent, -2.895 at 5 percent and -2.582 at 10 percent in DF and -5.34 percent at 1 percent, -4.80 at 5 percent and -4.58 at 10 percent in ZA)} affirming that said integrated series of order I is stationary.\par
Finally, the series of the Real Exchange Rate in first differences shows in the results \textbf{(-8.578 in the DF test and -9.5 in the ZA test)} that reject H0 in both tests \textbf{(-3.518 at 1 percent, -2.895 at 5 percent and -2.582 at 10 percent in DF and -5.34 percent at 1 percent, -4.80 at 5 percent and -4.58 at 10 percent in ZA)} affirming that said integrated series of order I is stationary.\par
In conclusion, in all integrated series of order I H0 is rejected and, therefore, they are stationary; so, a cointegration analysis will be carried out. In the first place, the optimal lags will be determined using a VAR model; in turn, the dichotomous variables that were mentioned in previous sections as exogenous variables are added.\par
The results show that according to the Bayesian Information Criterion the order one \textbf{(-16.5164)} is determined, the Hannan-Quinn Criterion stipulates an order of four \textbf{(-17.9533)} and the Akaike Information Criterion determines the order twelve \textbf{(-19.4033)}; so we proceed to work with both equations.\par
For the first equation with one lag, the number of cointegration equations is calculated using the \textit{“Johansen method”} (Morán, Bucybaruta, Rivera, 2013). According to the Information Criteria \textbf{(-17.11302 in SBIC and -17.41945 in HQIC)} it can be noted that there are three cointegration equations that will help us to create the Error Correction Model (VEC) by adding the lags of the equation that we are elaborating.\par
In the second equation with four lags, the cointegration equations were calculated where the Information Criteria \textbf{(-17.0929 in SBIC and -18.19574 in HQIC)} indicate that there are three cointegration equations that will help us to develop the Error Correction Model.\par
In the last equation with twelve lags, the cointegration equations were calculated where the Information Criteria \textbf{(-16.74103 in HQIC)} indicate that there are three cointegration equations that will help us to develop the Error Correction Model.
After analyzing the previous results, we proceed to develop the impulse response analysis which will help us to know the growth in the short and long term according to the dependent variable and the independent variables. \par
According to the results obtained, the impact of remittances on the economy that receives them is interesting, however, the behavior of the variables of the country that issued the remittances is strengthened or weakened depending on the currency of said country, the results they will be explained in the next section.\par
\end{frame}


\subsection{Downscale energy cascade of waves}
\label{subsection_cascade}

\begin{figure}
\centerline{
\includegraphics[width=8cm]{../Figs/fig_spect_energy_budg_c=100_N=3840}}
\caption{Spectral energy fluxes averaged over a long simulation for $c
= 100$ and $n = 3840$.  The fluxes are nondimensionalized by $\eps$
and plotted versus $k/k_f$.  }
\label{fig_seb}
\end{figure}

The spectral energy fluxes of total energy, KE and APE are plotted in
figure~\ref{fig_seb} as functions of $k/k_f$.
%
The fluxes are approximately zero at the wave numbers smaller than the
forced wave numbers.  They increase sharply at the forced wave numbers
to values close to $\eps$ for the total energy flux and to $0.5\eps$
for the KE and APE fluxes.  The fluxes then decrease to zero over the
dissipation range.
%
The energy is transferred from the forced wave numbers to the
dissipation wave numbers with a constant flux equal to the mean
forcing and dissipation rates.
%
There is an inertial range where the flux is constant and
equipartitioned between equal KE and APE fluxes.
%
However, at wave numbers $k \simeq 2 k_f$, the flux is not exactly
equal to $\eps$.  This is very likely related to the energy injection
at wave numbers for which the force is zero, which is due to the
non-quadraticity of the kinetic energy (see appendix~\ref{app_comp}).
%
Nevertheless this effect is non-negligible only for wave number of the
order of $k\simeq 2 k_f$, i.e.\ at the first harmonics of the forced
wave numbers, such that there is a clear and wide inertial range
between $k\gtrsim 3 k_f$ to the dissipation range starting at wave
number of the order of $k \sim 70 k_f$.

\begin{figure}
\centerline{\includegraphics[width=8cm]{../Figs/fig_Kolmo_c=20_N=3840}}
\caption{
Third order structure functions involved in the exact Kolmogorov law (\ref{eq_Kolmo})
averaged over a long simulation for $c = 20$ and $n = 3840$.
%
The structure functions are normalized by $4 \eps r$.
%
Black thick line, $\mean{ \delta J_L|\delta \uu|^2 }
+ c^2\mean{\delta u_L(\delta h)^2}$;
light thin line, $c^2\mean{\delta u_L (\delta h)^2}$;
dark thin line, $\mean{\delta J_L |\delta \uu|^2}$.
%
The dotted straight line shows $4 \eps_q r$,
where $\eps_q$ is the quadratic energy dissipation rate.
}
\label{fig_Kolmo}
\end{figure}

Figure~\ref{fig_Kolmo} shows the quantity $\mean{\delta J_L|\delta
\uu|^2 } + c^2\mean{\delta u_L(\delta h)^2 }$ (black thick line)
normalized by $4 \eps r$ for $c = 20$ and $n = 1920$.
%
In this section, the brackets $\mean{}$ denote the average over space
and time.
%
The dotted straight line shows the quantity $4 \eps_q r$, where
$\eps_q$ is the quadratic energy dissipation rate (see
appendix~\ref{app_comp}) which takes place at small scales.
%
We see that the Kolmogorov law (\ref{eq_Kolmo}) is well satisfied
between \Add{$r \simeq 0.02L_f$ and $r \simeq 0.1 L_f$}.  The dark and
light thin continuous lines correspond to the quantities $\mean{\delta
J_L|\delta \uu|^2 }$ and $c^2\mean{\delta u_L(\delta h)^2}$,
respectively.
%
These two quantities are nearly equal over the inertial and
dissipation ranges, which is consistent with a wave cascade when
$f=0$.
%
The agreement with the Kolmogorov law and the equality between
$\mean{\delta J_L|\delta \uu|^2 }$ and $c^2\mean{\delta u_L(\delta
h)^2}$ are the equivalents in the separation space of the plateau in
the total energy flux and the equality between $\Pi_K$ and $\Pi_A$,
respectively.

\begin{figure}
\centerline{
\includegraphics[width=8cm]{../Figs/fig_spatiotempspectra_c=20_Nh=3840}}
\caption{Spatio-temporal spectra of KE (dark lines) and APE (light
lines) for $c = 20$ and $n = 3840$ versus $\omega/\omega_l$, where
$\omega_l = c k$.  From the larger to the smaller spectra, $k/\delta k
= 12$, 27, 62, 143, 327, and 746.  }
\label{fig_spatiotemp_spectra}
\end{figure}

Figure~\ref{fig_spatiotemp_spectra} presents the spatio-temporal
spectra plotted as a function of the normalized frequency
$\omega/\omega_l$.
%\PA{Explain how these spectra have been calculated.}
In order to calculate these spectra, we have saved well-resolved time
series of $\hat d(\kk)$ and $\hat a(\kk)$ for wave numbers inside
particular shells such as $k\leqslant \kk<k+\delta k$, computed the
temporal spectrum of each signal and averaged over the wave numbers
inside each shell.
%
The spectra are strongly dominated by large peaks at $\omega =
\omega_l$ indicating that the characteristic frequency for each wave
number is the linear frequency.  However, the widening of the peaks
can be explained only by nonlinear effects.  \Add{The equipartition
between kinetic and potential energies is expected since the flow only
consists of gravity waves and the total energy is nearly equal to the
quadratic energy which is equal to the sum over all waves of their
equipartitioned quadratic energy.}

\subsection{Time- and space-averaged energy as a function of $c$}

\begin{figure}
\centerline{
\includegraphics[width=\halfwidth]{../Figs/fig_Emean_c}
\includegraphics[width=\halfwidth]{../Figs/fig_Emean_resol}
}
\caption{Time- and space-averaged energy
$\langle h|\uu|^2 + c^2 h^2 \rangle/2$
of the statistically stationary flows.
%
In (\textit{a}), the energy is divided by
$\sqrt{\eps}$ and plotted versus $c$ for 3 resolutions:
$n = 960$, dotted lines;
$n = 1920$, continuous lines and
$n = 3840$, dashed lines.
The cyan curves show the law $C_n \sqrt{\eps L_f c}$,
with $C_n$ a fit coefficient.
%
In (\textit{b}), the energy is divided by
$\sqrt{\eps L_f c}$ and plotted versus $n$
for six values of $c$ as indicated in the legend.
}
\label{fig_Evsc}
\end{figure}

Figure~\ref{fig_Evsc}(\textit{a}) shows the time- and space-averaged
energy for the statistically stationary flows divided by the square
root of the mean energy dissipation rate as a function of $c$ and for
three resolutions: $n = 960$, dotted lines; $n = 1920$, continuous
lines and $n = 3840$, dashed lines.
%
For all resolutions, the energy increases with $c$.  More precisely,
the curves can be well fitted to a law $E = C_n \sqrt{\eps L_f c}$
(blue lines).  However, the coefficient $C_n$ varies with the
resolution, i.e.\ with the effective Reynolds number.
%
This is very different from the case of isotropic turbulence where the
energy scales as $E \sim (\eps L_f)^{2/3}$ and does not vary with the
Reynolds number in the limit of very large Reynolds number.
%
Weak wave turbulence theory predicts an energy-flux law of the form $E
\propto \eps^{1/(N-1)}$, where $N$ is the number of waves involved
in the nonlinear interactions \cite[]{Nazarenko2011}.  Therefore, the
scaling $E = C_n \sqrt{\eps L_f c}$ would correspond to interactions
involving three waves.
%
However, the hypothesis needed for applying the weak wave turbulence
formulation are not fulfilled.

This effect of the increase of the energy with the resolution is
investigated in figure~\ref{fig_Evsc}(\textit{b}) where the quantity
$C_n = E/\sqrt{\eps L_f c}$ is plotted as a function of the
resolution.
%
For $c = 10$ (dotted line), the waves are not very fast and the
variation with the resolution is weak.
%
However, in the limit of very fast waves ($c>100$), the curves for the
different wave speeds nearly collapse and increase at least up to $n =
5760$.  The increase tends to saturate but it is difficult to know
from our results what is the scaling of $C_n$ as a function of the
resolution and if it really saturates for very large $n$ and $c$.
%
In order to decide on this issue, we would need to run simulations in
the very-fast-wave regime, $c>100$, and at very large resolutions $n >
5760$.  In this regime the energy fluctuations are large so
that the simulations would have to be carried out for very long time
in order to get a good convergence for the mean energy.  Since the
time step has to be extremely small in this regime, such simulations
would be too costly.

\subsection{Energy spectra}

We now turn to the study of the energy spectra.  A dimensional
analysis based on the assumption that the spectra only depend on
$\eps$, $c$ and $k_f$ gives the following general expression
\begin{equation}
E_{\alpha, \beta}(k) = k^{-\alpha} \eps^\beta   c^{2- 3\beta}
{k_f}^{\alpha -1 - \beta}, \label{eq_E_alpha_beta}
\end{equation}
where $\alpha$ and $\beta$ are two free parameters.

\begin{figure}
\centerline{
\includegraphics[width=\halfwidth]{../Figs/fig_spectra_c_Nx=1920_k32}
\includegraphics[width=\halfwidth]{../Figs/fig_spectra_c_Nx=3840_k32}
}
\centerline{
\includegraphics[width=\halfwidth]{../Figs/fig_spectra_c_Nx=1920_k2}
\includegraphics[width=\halfwidth]{../Figs/fig_spectra_c_Nx=3840_k2}
}
\caption{
Compensated energy spectra versus $k/k_f$ for different wave speeds $c$.
%
The spectra are compensated by $k^{-3/2}\sqrt{\varepsilon c} $
in (\textit{a,b})
and by $k^{-2}c^{1/3} \eps^{5/9} k_f^{4/9} $
in (\textit{c,d}).
%
The resolution is
$n = 1920$ in (\textit{a,c}) and
$n = 3840$ in (\textit{b,d}).
%
In (\textit{a,c}), the wave speed goes from 10 to 1000
and
in (\textit{b,d}) from 10 to 200
(for the precise values, see figure~\ref{fig_Evstime}).
}
\label{fig_spectra_c}
\end{figure}

The scaling of the energy as $\sqrt{\eps L_f c}$ suggests that the
spectra should scale like the Zakharov-Sagdeev spectrum, $E(k) \sim
k^{-3/2}\sqrt{\eps c}$, which is the prediction of weak wave
turbulence theory for three-dimensional acoustic turbulence
\cite[]{Nazarenko2011}.
%
The compensated spectra $E(k) / ( k^{-3/2}\sqrt{\eps c})$ are plotted
in figure~\ref{fig_spectra_c}(\textit{a}) for $n = 1920$ and in
figure~\ref{fig_spectra_c}(\textit{b}) for $n = 3840$.  The different
curves correspond to different wave speeds, going from $c=10$ to
$c=1000$ for $n = 1920$ and from $c=10$ to $c=200$ for $n = 3840$.
%
For both resolutions, the compensated spectra collapse at the
energy-dominating small wave numbers.
%
However, these compensated spectra are not flat in the inertial range
and do not collapse in the inertial and dissipation ranges, i.e. for
$k\gtrsim 2k_f$.  In the inertial range, they follow a clear $k^{-2}$
scaling law and there is a bottleneck in the dissipation range where
the slope is close to $-3/2$.
%
\cite{Kuznetsov2004} showed that $k^{-2}$ spectra can be explained by
singularities and this scaling has already been observed in
two-dimensional acoustic turbulence \cite[]{FalkovichMeyer1996}.
%

Inserting $\alpha = 2$ in the spectrum (\ref{eq_E_alpha_beta}) gives
\begin{equation}
E_\beta(k) = k^{-2} {k_f}^{1-\beta} c^{2-3\beta} \eps^\beta
\end{equation}
and we have found that the numerical spectra are very close to the
spectrum $E_\beta(k)$ with $\beta = 5/9$.
%
The compensated spectra $E(k) / ( k^{-2} c^{1/3} \eps^{5/9} k_f^{4/9}
)$ are plotted in figure~\ref{fig_spectra_c}(\textit{c}) for $n =
1920$ and in figure~\ref{fig_spectra_c}(\textit{d}) for $n = 3840$.
The collapse is very good in the inertial range but we stress that we
are not aware of any theory predicting the empirical spectrum $k^{-2}
c^{1/3} \eps^{5/9} k_f^{4/9}$.

\begin{figure}
\centerline{\includegraphics[width=8cm]{../Figs/fig_spectra_c=40_nh=7680}}
\caption{Compensated spectra
of total energy (thick black line)
kinetic energy (thin dark line) and
available potential energy (thin light line)
for $c = 40$ and $n = 7680$.}
\label{fig_spectra_c40}
\end{figure}

Figure~\ref{fig_spectra_c40} shows the compensated spectra $E(k) / (
k^{-2} c^{1/3} \eps^{5/9} k_f^{4/9} )$ of total energy (black line),
KE (red line) and APE (blue line) for $c = 40$ and $n = 7680$.  For
all wave numbers, we have $E(k) = 2E_K(k) = 2E_A(k)$ since the flow
only consists of \Add{gravity} waves.
%
The spectra are very close to $k^{-2}$ in the inertial range over more
than one decade and the shallowing to a slope close to $-3/2$ is
clearly confined to the dissipation range.  This confirms that this
bump is due to a dissipation effect and that there is no wide
$k^{-3/2}$ spectrum even at very large resolutions.

% \begin{figure}
% \centerline{
% \includegraphics[width=\halfwidth]{../Figs/fig_spectra_resol_c=10}
% \includegraphics[width=\halfwidth]{../Figs/fig_spectra_resol_c=40}
% }
% \caption{Compensated energy spectra $E(k) / ( k^{-3/2}\sqrt{\eps c})$
% for different resolutions.  In (\textit{a}), $c = 10$ and in
% (\textit{a}), $c = 40$.}
% \label{fig_spectra_resol}
% \end{figure}

% The compensated spectra $E(k) / ( k^{-3/2}\sqrt{\eps c})$ are plotted
% for different resolutions %
% in figure~\ref{fig_spectra_resol}(\textit{a}) for $c=10$ and
% in figure~\ref{fig_spectra_resol}(\textit{b}) for $c=40$.
% %
% We see that an inertial range with a $k^{-2}$ scaling starts to appear
% for $n\gtrsim 960$.
% %
% As seen in figure~\ref{fig_Evsc}, the ratio $E/\sqrt{\eps L_f c}$ only
% weakly varies for $c=10$ but increases in the fast-waves regime for
% $c=40$.  This effect can be seen here at the energy-containing wave
% numbers $k<2 k_f$.  However, the variation with the resolution is much
% weaker in the inertial range at $k>2 k_f$.

In subsection~\ref{subsection_cascade}, we have shown that third-order
structure functions scale like $r$ since there is a downscale energy
cascade.
%
The Kolmogorov method predicts $k^{-5/3}$-spectra but the numerical
spectra are much steeper in the inertial range, with a slope equal to
-2.  The fact that third-order and second-order quantities can not be
simply related by the Kolmogorov scaling implies that the cascade is
very intermittent.

\subsection{Effect of the shocks and intermittency}

\begin{figure}
\setlength{\halfwidth}{69mm}
\centerline{
\includegraphics[width=\halfwidth]{../Figs/fig_2Dh_c20}
\hspace{-4mm}
\includegraphics[width=\halfwidth]{../Figs/fig_2Dh_c200}
}
\centerline{
\includegraphics[width=\halfwidth]{../Figs/fig_2Duy_c20}
\hspace{-4mm}
\includegraphics[width=\halfwidth]{../Figs/fig_2Duy_c200}
}
\caption{
Snapshots for $n = 1920$ and two values of the wave speed
$c= 20$ (\textit{a,c}) and $c= 200$ (\textit{b,d}).
The colors represent the thickness in (\textit{a,b}) and
the $y$-component of the velocity in (\textit{c,d}).
The arrows represent the velocity field.
%
The coordinates are nondimensionalized by the characteristic scale of
the forcing $L_f = 3.57$.  }
\label{fig_phys}
\end{figure}

Figure~\ref{fig_phys} shows %
the normalized thickness $h$ %
(figures~\ref{fig_phys}\textit{a,b}) %
and the $y$-component of the velocity $u_y$ %
(figures~\ref{fig_phys}\textit{c,d}) %
for $c = 20$ (figures~\ref{fig_phys}\textit{a,c}) and %
$c = 200$ (figures~\ref{fig_phys}\textit{b,d}).
%
These wave speeds correspond %
to a moderate forcing Froude number $F_f \sim 0.05$ and %
to a very small forcing Froude number $F_f \sim 0.005$, respectively.
The normalized surface displacement $\eta = h - 1$ is of order 0.3 for
$c = 20$ and one order of magnitude smaller, 0.03, for $c = 200$.
%
The typical velocity is also much smaller than the wave speed, %
with $u_y/c \sim 0.2$ for $c = 20$ %
and $u_y/c \sim 0.03$ for $c = 200$. %
This confirms that the flows are in a fast-wave regime, especially for
$c = 200$.
%
However, many discontinuities can be seen in both fields $h$ and
$u_y$.  These discontinuities are hydraulic jumps, which are the
equivalent to shocks in a compressible flows.
%
\Add{Baines (1998) provides a theoretical prediction for the velocity
of the hydraulic jumps is one-layer shallow-water flow:
\begin{equation}
c_s = c \sqrt{\frac{h_+}{h_-} \frac{h_+ + h_-}{2}},
\end{equation}
where $h_+$ and $h_-$ are the dimensionless thickness before and after
the jump.
%
We have verified that the velocity of the discontinuities in the
simulations is consistent with this theoretical prediction, implying
that the associated Froude number (or Mach number) is of the order
unity.}

\nocite{Baines1998}

% We have verified that these shocks are very fast and travel at a
% velocity of the order of the wave speed \Add{(more precisely, Baines 1998)}
% , implying
% that their associated Froude number (or Mach number) is of the order
% unity.
%el (This is not necessarily true...)
% The existence of shocks implies that there is a strong coherence
% between small and large wave numbers and indicates nonlocal
% interactions between wave numbers.
%
In between the shocks, the flow is very smooth for $c=20$ and slightly
more irregular for $c = 200$.

Figures~\ref{fig_phys}(\textit{c,d}) display the $y$-component of the
velocity.  There are less discontinuities in this quantity than in the
thickness. More precisely, the $h$-discontinuity lines that are along
the $y$-axis are not associated with corresponding discontinuities of
the $y$-component of the velocity. This can be seen for example for
the shock at $x/L_f\simeq 0.4$ and $y/L_f\simeq 2.1$ in
figures~\ref{fig_phys}(\textit{a}) and \ref{fig_phys}(\textit{c}).
%
This illustrates that the singularity in the velocity is in the
component perpendicular to the shock line, which is the assumption on
the structure of the velocity discontinuities used in the model
presented in \S~\ref{subsection_shock_model}.

\begin{figure}
\centerline{
\includegraphics[width=\halfwidth]{../Figs/fig_interm_strfct_ux}
\includegraphics[width=\halfwidth]{../Figs/fig_interm_strfct_uy}
}
\caption{
Compensated fifth-order structure functions $\mean{|\delta u_L|^5}/r$
of (\textit{a}) the longitudinal increments and (\textit{b}) the
transverse increments. %
The crosses indicate the range of separation $r$ where the exponent
$\zeta_p$ is computed. %
The dashed lines correspond to the Kolmogorov scaling laws $r^{p/3}$
and $\zeta_p = p/3$.  The wave speed and the resolution are $c = 40$
and $n = 7680$.  }
\label{fig_strfct5}
\end{figure}

The shock model derived in subsection~\ref{subsection_shock_model}
predicts that structure functions of all orders should scale linearly
with $r$.
%
Figure~\ref{fig_strfct5} presents fifth-order structure functions
compensated by $r$.
%
Figures~\ref{fig_strfct5}(\textit{a}) and
\ref{fig_strfct5}(\textit{b}) correspond to the structure functions
computed from the longitudinal increments and the transverse
increments, respectively.  The structure functions compensated by $r$
are nearly flat between $r \simeq 0.012 L_f$ and $r \simeq 0.06 L_f$,
showing that they scale like $r$ on this relatively narrow range of
scale compared to the inertial range.
%
The $r$-scaling is very different from the slope of the fifth-order
structure functions calculated from the Kolmogorov scaling $\zeta_5 =
p/3 \simeq 1.66$ (dashed straight line).  This shows that the wave
cascade is strongly intermittent and that this intermittency can be
explained by the presence of discontinuities related to the shocks.

\begin{figure}
\centerline{
\includegraphics[width=\halfwidth]{../Figs/fig_interm_ux}
\includegraphics[width=\halfwidth]{../Figs/fig_interm_uy}
}
\caption{
Exponents $\zeta_p$ of the structure functions
of (\textit{a}) the longitudinal increments
and (\textit{b}) the transverse increments versus the order $p$.
%
The dashed lines correspond to
the Kolmogorov scaling laws $r^{p/3}$ and $\zeta_p = p/3$.
The wave speed and the resolution are $c = 40$ and $n = 7680$.
}
\label{fig_interm}
\end{figure}

The slope of the structure functions of order $p$ over the range
$0.012 L_f\leqslant r \leqslant 0.06 L_f$, $\zeta_p$, are plotted in
figure~\ref{fig_interm}(\textit{a}) for the longitudinal increments
and in figure~\ref{fig_interm}(\textit{b}) for the transverse
increments.
%
The exponent are very far from the Kolmogorov scaling $\zeta_p = p/3$.
They increase as $p$ for $p\ll1$, saturate to a value close to 1 for
$p>2$ and tend to decrease for $p>3$.
%
A similar shape of the $\zeta_p$ function has been predicted for
Burger turbulence \cite[]{BouchaudMezardParisi1995}.
%
The shape of $\zeta_p$ at very small $p$ is determined by the
scaling of the smallest velocity increments and the $p^1$-variation
shows that these smallest increments scales like $\delta u \sim r^p$.
%
The plateau at $p > 2$ is a consequence of the dominance by shocks of
the largest increments.
%
Note that these results are obtained for a relatively small forcing
Froude number $F_f \simeq 0.03$ corresponding to $c=40$.  The function
$\zeta_p$ has approximately the same extreme shape for a larger Froude
number $F_f \simeq 0.01$, corresponding to $c=10$.  Note also that the
decrease of $\zeta_p$ for $p>3$ is anomalous, which could be due to
the relatively narrow width of the range over which $\zeta_p$ is
computed.

\begin{figure}
\centerline{
\includegraphics[width=\halfwidth]{../Figs/fig_ratio_strfct}
}
\caption{
Ratio of the structure functions of the velocity increments
$R_p(r) \equiv \mean{|\delta u_L|^p} / \mean{|\delta u_T|^p}$
for $p = 2,$ 3 and 4.
The dotted straight lines indicate the values computed by the shock model:
$R_2 = 2$, $R_3 = 6\pi/8$ and $R_4 = 8/3$.
%
The wave speed and the resolution are $c = 10$ and $n = 7680$.  }
\label{fig_ratio}
\end{figure}

The functions $R_p = \mean{|\delta u_L|^p}/\mean{|\delta u_T|^p}$ are
plotted in figure~\ref{fig_ratio} for $p =2$ to 4.  The predictions of
the shock model, $R_2 = 2$, $R_3 = 6\pi/8$ and $R_4 = 8/3$, are also
plotted in dotted lines for comparison.  We see that the numerical
results are reasonably close to these predictions.  However, the
agreement is less good for smaller Froude number (not shown).  The
structure functions are fully determined by shocks only for Froude
numbers that are not too small, which is consistent with the snapshots
in figure~\ref{fig_phys} showing that the fields between the shocks
are more irregular for the smallest Froude number.

\begin{figure}
\centerline{
\includegraphics[width=\halfwidth]{../Figs/fig_flatness}
}
\caption{ Flatness of the longitudinal and transverse increments for
$c = 10$ and $n = 7680$. The straight continuous lines indicate the
$r^{-1}$-scaling and the straight dashed line the $r^{-3/2}$-scaling.
The inset shows the ratio $F_T/F_L$ and the corresponding value
computed by the shock model, $F_T/F_L = 1.5$.  }
\label{fig_flatness}
\end{figure}
%
Figure~\ref{fig_flatness} shows the flatness of the longitudinal and
transverse increments, computed from a numerical simulation for $c =
10$ and $n = 7680$.
%
For a Gaussian probability distribution the flatness factor is equal
to 3 whereas the shock model predict flatness factors scaling like
$r^{-1}$.
%
We see that here the flatness factors are much larger than 3, of the
order of $10^3$.
%
Remarkably, they scale approximately as $r^{-1}$ as predicted by the
shock model and the ratio $F_T/F_L$ is very close to the predicted
value 1.5.

% Figure~\ref{fig_flatness}(\textit{b}) shows the same quantities
% computed from atmospheric data measured by commercial aircraft.
% %
% The flatness curves have been taken from \cite{Lindborg1999}.
% Surprisingly, the atmospheric results are quite similar to the
% numerical ones. The flatness factors are very large and strongly
% decrease at scales smaller than 100 km.  Interestingly, the ratio
% $F_T/F_L$ is also very close to the value 1.5 predicted by the shock
% model.
% %
% We stress that even though these similarities are striking, the
% underlying dynamics are very different.
% %
% While there is no energy in the quasi-geostrophic modes in the
% numerical simulations, the atmospheric flows are usually close to be
% quasi-geostrophic at horizontal scales larger than 500 km and the
% vertical vorticity is in average of the same order of magnitude than
% the horizontal divergence at the mesoscales, i.e. at horizontal scales
% between 10 and 500 km \cite[]{Lindborg2007jas}.
% %
% Therefore, it is not surprising to also see differences between the
% atmospheric and the numerical results. The flatness factors in
% figure~\ref{fig_flatness}(\textit{b}) vary approximately as $r^{-3/2}$
% (dashed line), which is significantly faster than for the numerical
% simulations of the shallow-water model. Moreover, the second-order
% structure functions in the atmosphere scale as $r^{2/3}$
% \cite[]{Lindborg1999, ChoLindborg2001,
% FrehlichSharman2010}. Considering the scaling for the flatness
% factors, this implies that the variation with scale of the
% fourth-order structure functions is actually very weak, which is
% not in agreement with the prediction of the shock model.
% %
% Nevertheless, we do not know other explanations of such very large
% flatness factors with a ratio $F_T/F_L=1.5$ observed in the atmosphere.
% %
% Thus, we think that these results raise interesting questions
% regarding the interpretation of structure functions measured in the
% atmosphere.  How important are the discontinuities on horizontal
% cross-sections in these cases?
% %
% It is well known that the fronts separating cold and warm regions
% explain many meteorological phenomena.
% %
% The curves in figure~\ref{fig_flatness} seem to indicate that
% they could also have strong effects on the statistics of the atmosphere
% over a quite large range of scales.


\section{Overview}

%%%%%%%%%%%%%%%
\begin{frame}{Contents of Tutorials}
  Overview:
  \begin{enumerate}
    \item Graph Decomposition {\scriptsize (vs. Graph Traversal)}
    \item MST \& Path $\Rightarrow$ Greedy Algorithm
    \item DP: Dynamic Programming
  \end{enumerate}
\end{frame}
%%%%%%%%%%%%%%%
\begin{frame}{Graph Decomposition}
  Graph decomposition vs. Graph traversal
  \begin{itemize}
    \item objects: integer vs. graph
    \item graph traversal as basis
    \item structure matters
      \begin{itemize}
	\item states of vertices
	  \begin{itemize}
	    \item undiscovered $\to$ discovered $\to$ finished
	    \item white $\to$ gray $\to$ black
	  \end{itemize}
	\item types of edges
	  \begin{itemize}
	    \item tree edge, back edge, forward edge, cross edge
	  \end{itemize}
	\item DFS: lifetime of vertices
	  \begin{itemize}
	    \item $v: \text{d}[v], \text{f}[v]$
	    \item $\text{f}[v]$: DAG, SCC
	    \item $\text{d}[v]$: biconnectivity
	  \end{itemize}
      \end{itemize}
  \end{itemize}
\end{frame}
%%%%%%%%%%%%%%%


% !TEX root = ../../main.tex
% !TEX spellcheck = en_GB

\section{Analysis}
In contrast to the pure sine, the C-major consists of several frequencies, as shown in \cref{fig:fftc4}.

\begin{figure}
	\centering
	\includegraphics[width=0.7\linewidth]{gfx/fft_C4.png}
	\caption{Frequency spectrum of C$_4$ played on a piano \cite{fft_c4}.}
	\label{fig:fftc4}
\end{figure}

These frequencies are evenly spaced, and the solutions presented in \cref{sec:simpleanal} are still valid to use.
Here the solution of changing the sampling frequency is still not valid due to limitations on the Blackfin, and the primary target of the analysis is if it is possible to use the same approach as in the pure sine implementation: Creating a new tone at the target frequency.

The approach again focuses on the steps
\begin{enumerate}
	\item Find the input tone.
	\item Create new tone at target frequency.
	\item Play output tone.
\end{enumerate}

\paragraph{Finding the input tone}
In the sine part, the frequency was found using Instantaneous Frequency.
This approach may still be valid, but would require the ratio between the fundamental and every harmonic frequency to be exactly the same each time.
Should the ratios for the fundamental and the first to harmonics be e.g. 3, 2 and 1, the output of the Instantaneous Frequency would be as shown in \cref{tab:CmajorIF}.

\begin{table}
	\centering
	\begin{tabular}{l c}
		\toprule
		Note & IF \\
		\midrule
		C$_4$ & \num{436.043} \\
		D$_4$ & \num{489.442} \\
		E$_4$ & \num{549.380} \\
		F$_4$ & \num{582.047} \\
		G$_4$ & \num{653.325} \\
		A$_4$ & \num{733.333} \\
		B$_4$ & \num{823.138} \\
		\bottomrule
	\end{tabular}
	\caption{IF values if including the first two harmonic frequencies.}
	\label{tab:CmajorIF}
\end{table}

Another approach could be to use FFT to determine the tallest peak, leading to a not very accurate measurement, approximately \SI{\pm50}{\hertz}, bandpass filter this frequency bin, removing everything else, and the calculate the Instantaneous Frequency.
The found frequency can then be compared to a table of the C-major frequencies and their harmonics, allowing the tone to be determined.
Then the new pitch shifted tone can be created with a number of harmonics.