\chapter{Second Order Force Calculations}
\label{chap:2ndOrdCalc}

In this chapter, the equations and algorithms used to find the second order hydrodynamic forces from the output of WAMIT are discussed.
The forms of the equations presented here are what is used in the WAMIT2 module within HydroDyn.
  Along with the equations, the methodology and processing necessary to take the WAMIT output file types and parse them for use in the equations is also covered in detail.
The interpolation algorithms used are covered in \Cref{chap:Algorithm}.

\Cref{tab:Wamit2MethodsByFileType} shows which calculations methods can be used depending on what WAMIT output files are available.  The criteria for downselecting information in the file for use in the calculations is given for each method and file type combination.
\input{chaps/tables/Chap.WamitOutput.Options.tex}

The notation used in this chapter is given in \Cref{tab:2ndOrdNotation} (note that this differs slightly from the notation in the WAMIT manual\cite{WAMIT} and in Tiago's writings\cite{duarte:2014}).
\begin{table}[h!]
   \centering
   \caption{Notation used in the second order force equations.
            The variable name used in the fortran code is also listed where appropriate.
            \label{tab:2ndOrdNotation}}
   \begin{tabular}{ccl}
      \toprule
         Variable          & Fortran Variable      &  Description                                                       \\
      \midrule
      $A_m$                &                       &  \parbox[t]{3.5in}{Complex amplitude of the $m^\text{th}$ frequency
                                                               given in $Z[m]$ array from the \emph{Waves} module.  This
                                                               includes a $N/2$ term in it.}                            \\[13pt]
      $a_m$                &                       &  \parbox[t]{3.5in}{Complex amplitude of the $m^\text{th}$ frequency
                                                               given in $Z[m]$ array from the \emph{Waves} module.  This
                                                               has the $N/2$ term removed.}                             \\[13pt]
      $i$                  & \varname{ImagNmbr}    &  \parbox[t]{3.5in}{The imaginary number $i = \sqrt{-1}$ ($i$ and
                                                               $j$ are not used as indices here to avoid confusion)}    \\[13pt]
      $k$                  &                       &  Index to load component (translation: 1 -- 3; rotation: 4 -- 6)   \\
      $m$                  &                       &  Index to first wave                                               \\
      $n$                  &                       &  Index to second wave                                              \\
      $\mu^\text{-}$       &                       &  Difference index of two waves frequencies ($= m-n$)               \\
      $\mu^{+}$            &                       &  Summation  index of two wave frequencies ($= m+n$)                \\
      $\tau$               & \varname{WAMITPer}    &  Period of wave in WAMIT file                                      \\
      $\tau_1$             & \varname{WAMITPer1}   &  Period of first wave in pair read from WAMIT file                 \\
      $\tau_2$             & \varname{WAMITPer2}   &  Period of second wave in pair read from WAMIT file                \\
      $\omega$             & \varname{Omega}       &  Frequency (rad/s)                                                 \\
      $N$                  & \varname{NStepWave}   &  Total number of timesteps (range 0:N)                             \\
      $N/2$                & \varname{NStepWave2}  &  Total number of positive wave frequencies (range 0:N/2)           \\
      $Z(\omega_m)$        & \varname{WaveElevC0}  &  The discretized complex wave form in the frequency domain         \\
      $\Phi(\omega_m)$     & \varname{WaveDir}     &  Wave direction for each wave frequency                            \\
      $t_\text{max}$       & \varname{WaveTMax}    &  The maximum time of the wave simulation                           \\
      $\Delta t$           & \varname{WaveDT}      &  The timestep for the wave simulation                              \\
      $\omega_\text{lo}$   & \varname{WvLowCOff}   &  The low frequency cutoff for first order waves                    \\
      $\omega_\text{hi}$   & \varname{WvHiCOff}    &  The high frequency cutoff for first order waves                   \\
      $\Delta\omega$       & \varname{WaveDOmega}  &  The frequency stepsize                                            \\
      $\omega_\text{lo-d}$ & \varname{WvLowCOffD}  &  Difference frequency low-cutoff                                   \\
      $\omega_\text{hi-d}$ & \varname{WvHiCOffD}   &  Difference frequency high-cutoff                                  \\
      $\omega_\text{lo-s}$ & \varname{WvLowCOffS}  &  Sum frequency low-cutoff                                          \\
      $\omega_\text{hi-s}$ & \varname{WvHiCOffS}   &  Sum frequency high-cutoff                                         \\
      $\bar{F}^\text{-}_{k}$ &                     &  \parbox[t]{3.5in}{$k^\text{th}$ component of the non-dimensional difference
                                                                     frequency transfer matrix (data from WAMIT)}       \\[13pt]
      $F^\text{-}_{k}$     &                       &  \parbox[t]{3.5in}{$k^\text{th}$ component of the dimensionalized difference
                                                                     frequency transfer matrix}                         \\[13pt]
      $\bar{F}^\text{+}_{k}$ &                     &  \parbox[t]{3.5in}{$k^\text{th}$ component of the non-dimensional sum
                                                                     frequency transfer matrix (data from WAMIT)}       \\[13pt]
      $F^\text{+}_{k}$     &                       &  \parbox[t]{3.5in}{$k^\text{th}$ component of the dimensionalized sum
                                                                     frequency transfer matrix}                         \\[13pt]
      $\rho g$             & \varname{RhoXg}       &  Water density * gravity                                           \\
      $L$                  & \varname{WAMITULEN}   &  WAMIT characteristic body length scale                            \\
   \end{tabular}
\end{table}

\section{Overview}
\label{sec:2ndOrdCalc:Overview}

\begin{figure}[ht]
   \begin{center}
      \beginpgfgraphicnamed{General.Flowchart}
         \input{chaps/figures/General.Flowchart.tikz.tex}
      \endpgfgraphicnamed
   \end{center}
\caption{Generalized overview calculation of second order forces.  Here $Z(\omega)$ is the combination complex wave as a function of frequency and $\Phi(\omega)$ is the associated wave direction heading for each frequency.
The 3D and 4D arrays containing the wave force transfer function are interpolated at each step within the innermost summation containing the $F^\pm_k$ terms, or during assembly of the matrix for the FFT.
   \label{fig:General:Flowchart}
}
\end{figure}

In order to simplify the data processing as much as possible, the WAMIT output data will sorted and stored in either a three-dimensional matrix for first order derived transfer matrices (.7, .8, and .9 files), or a four-dimensional for data derived by full QTF methods (.10, .11, and .12 files).  The values needed for each step in the calculation are interpolated from these arrays using either three- or four-dimensional linear interpolation subroutines (see \Cref{chap:Algorithm} for details on the interpolation). The interpolation of $F^\pm_k$ occurs within each step of the summation or during the assembly of the FFT array.  This minimizes the memory storage requirements somewhat.

\clearpage

\section{Frequency range}
\todo[inline]{Add discussion of Nyquist frequency and its effects -- see e-mail and discussion within the code}
The number of timesteps used in the \modname{Waves} module is determined by the total time, $t_\text{max}$, and timestep, $\Delta t$, specified for wave information (\varname{WaveTMax} and \varname{WaveDT} in the \HD input file and code).  The number of timesteps (\varname{NStepWave}) is then set to at least $N \geq  \left(\frac{t_\text{max}}{\Delta t}\right)$ such that $N$ is even and $N/2$ is a product of small numbers (this is advantageous in computing the FFT).
The number of timesteps also limits the number of frequencies present in the wave information to $N/2+1$ frequencies with a maximum frequency of $1/(2 \Delta t)$ in Hz (the Nyquist frequency).
The maximum wave frequency is therefore $\omega_\text{max} = N/2 \cdot \Delta\omega$ where $\omega$ is in radians.
Due to the specifics of the FFT used (see \Cref{sec:Algorithm:FFT}, the number of frequencies stored in the wave information is $N/2+1$ where only positive frequencies are used (values for $\omega < 0$ are derived from the values for $\omega > 0$).
The full expression for $N$ in can be written as
\begin{equation}
   N = \dfrac{t_\text{max}}{\Delta t} = \dfrac{2 \omega_\text{max}}{\Delta \omega} = \frac{ 2 \pi}{\Delta t \Delta \omega}.
\label{eq:N}
\end{equation}

Three sets of wave frequency cutoffs are applied to the wave conditions.  The first order frequency range is bounded by the limits $\omega_\text{lo}$ and $\omega_\text{hi}$ (set in the \HD input file by \varname{WvLowCOff} and \varname{WvHiCOff}).  These limits are imposed during generation of the wave frequencies in the \modname{Waves} module by setting the amplitudes of $Z(\omega)=0$ for all $\omega$ outside the limits.

The second order wave frequency limits for all three difference methods are given by $\omega_\text{lo-d}$ and $\omega_\text{hi-d}$ (\varname{WvLoCoQTFd} and \varname{WvHiCoQTFd}).
In the case of the mean-drift and Newman's approximation methods where only the diagonal elements (where $\omega_1 = \omega_2$) are considered, the low difference frequency cutoff will likely not have any impact since it will be rare that $\omega_\text{lo-d} > \omega_\text{lo}$ (a warning will be issued if this does occur).\footnote{The mean drift and Newman's approximation will automatically be zeroed for frequencies less than $\omega_\text{lo}$ since they contain $a_m$ terms for each $\omega_m = \omega_m$ diagonal term.}  The high frequency cutoff will likely be set so that $\omega_\text{hi-d} < \omega_\text{hi}$, so this will be important to impose (a warning will be issued if this is not true).

%\todo[inline]{Add warning in code if $\omega_\text{lo-d} > \omega_\text{lo}$ for either mean drift or Newman's.  Did I do this already?}
%\todo[inline]{Add warning in code if $\omega_\text{hi-d} > \omega_\text{hi}$ for either mean drift or Newman's.  Did I do this already?}

The second order wave frequency limits for the full second order QTFs are then set for the difference QTF and sum QTF methods individually.
For the difference QTF method these limits are given by  $\omega_\text{lo-d}$ and $\omega_\text{hi-d}$ (\varname{WvLowCOffD} and \varname{WvHiCOffD}).
For the sum QTF method these limits are given by  $\omega_\text{lo-s}$ and $\omega_\text{hi-s}$ (\varname{WvLowCOffS} and \varname{WvHiCOffS}).
These limits are applied during the summations of the $a_m a_m F(\omega_m,\omega_m)$ and $H_{\mu^\pm}$ terms.

%\missingfigure{add in the figure from p. 145 of notebook}

\section{Wave Amplitude}
\label{sec:2ndOrdCalc:WaveAmp}

The complex wave amplitude in frequency space, $Z(\omega)$, provided by the \modname{Waves} module contains an extra $N/2$ factor on the amplitude.  This factor is not present in the equations given in Ref.~\citen{duarte:2014}.
The relationship between the amplitude provided by the \modname{Waves} module, $A_m$ and the amplitude used in the paper, $a_m$, is
\begin{equation}
   A_m = \frac{N}{2} a_m.
\label{eq:WaveAmp}
\end{equation}
In the initialization of the \modname{WAMIT2} module, the values stored for the wave elevation from the \modname{Waves} module are divided by $N/2$ before being stored in the \varname{aWaveElevC0} variable.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Difference Frequency Force}
\label{sec:2ndOrdCalc:Diff}

There are three methods for calculating the difference frequency force: mean drift, Newman's approximation, and through the full QTF.  Each method has its advantages, and has different data requirements.  In this section, we explore the simplified equations used in the \modname{WAMIT2} module, the data requirements, and the data processing steps for each of the three methods.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Mean-Drift Method}
\label{sec:2ndOrdCalc:Diff:MeanDrift}
This term arises from the quadratic interactions of the first order problem, and can therefore be calculated without requiring solutions to the second order potential.  This equation is identical to the first part of the difference QTF equation, \Cref{eq:DiffQTF}, where just the diagonal elements of the QTF are used.  This is the simplest of the three difference frequency methods presented here. The single summation equation is given by
\begin{equation}
   {F_{\text{ex}~k}^{\text{-}(2)}} =
            \Re \left( \sum\limits_{m=1}^{N/2}
                  {a_m} {a_m^*} F_k^\text{-}(\omega_m, \beta_m)\right) \qquad
      \text{for}\quad k=1,2,\ldots,6,
\label{eq:MeanDrift}
\end{equation}
where $k$ indicates the index to the load component,  ${F_{\text{ex}~k}^{\text{-}(2)}}$ is the resulting time independent mean drift force, and $a_m$ and $a_m^*$ are the complex wave amplitude and its complex conjugate for the $m$\textsuperscript{th} frequency.  Note the lack of time dependence in this equation: the mean drift is the average drift force over the entire simulation.
Note that $F_k^\text{-} (\omega_m, \beta_m)$ is the dimensionalized real valued diagonal of the QTF read from the WAMIT file and interpolated for the $m$\textsuperscript{th} wave frequency.  Note that the $\Delta\omega$ term is necessary since this is a numerical integral.
Note also that the summation starts at $m=1$.  The value of $a_0$ is exactly 0, so it does not need to be included.

\begin{figure}[ht]
   \begin{center}
      \beginpgfgraphicnamed{MeanDrift.Flowchart}
         \input{chaps/figures/MeanDrift.Flowchart.tikz.tex}
      \endpgfgraphicnamed
   \end{center}
\caption{Flow diagram for the mean drift calculation method.  The mean drift equation only involves the diagonal terms where the frequencies $\omega_1 = \omega_2$, and the wave directions $\beta_1 = \beta_2$.
The WAMIT output files are read in and arranged in either a 3D or 4D array and interpolated at each step in the summation.
See text for how to solve the equation. See \Cref{chap:WamitOutput} for requirements on which WAMIT output files can be used.
   \label{fig:MeanDrift:Flowchart}
}
\end{figure}

\subsubsection*{Solving the Mean-Drift Equations}
\label{sec:2ndOrdCalc:Diff:MeanDrift:solve}
As shown in \Cref{fig:MeanDrift:Flowchart}, the data is stored in either 3D or 4D arrays depending on the file type used.  This is handled by the WAMIT output file reading subroutine, \rname{Read\_DataFiles}, within the \modname{WAMIT2} module.  At each step in the summation of the $m$\textsuperscript{th} term, a call is made to the 3D or 4D interpolation algorithm to find the value of $F^\text{-}_k (\omega_m, \beta_m)$ corresponding to the $Z (\omega_m)$ term in the complex wave amplitude $a_m$.  The limits of $\omega_\text{lo-d} \le \omega_m \le \omega_\text{hi-d}$ are imposed during the summation with values outside this range set to zero.

For multi-directional waves where the equal energy discretization is used, each frequency has a single wave direction associated with it.  Since the mean drift force calculation only involves summing over terms involving only a single frequency at a time, only a single wave direction is involved at each step.  If all the diagonal elements where $\omega_1 = \omega_2$ and $\beta_1 = \beta_2$ were present in the $F^\text{-}_k$ arrays were present, it would be possible to simplify the interpolation required to two dimensional interpolation.  However, since this calculation is performed only at initialization, the calculation penalty for performing a full 3D or 4D interpolation is not as severe as it would be if it were performed at each timestep of the simulation.  Therefore we are choosing to ignore this in favor of simplifying the code implimentation.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\clearpage
\subsection{Newman's Approximation Method}
\label{sec:2ndOrdCalc:Diff:Newman}

Newman's original approximation:
\begin{align}
   {F_{\text{ex}~k}^{- (2)}} &\approx
            \left.   \left[ \Re \left( \sum\limits_{m=1}^{N/2}
                     {a_m} \sqrt{   2 F_k^{-}(\omega_m,\omega_m)}
                     \cdot \mathrm{e}^{\iu \omega_m t} \right) \right]^2 \right|_{F_{k}^{-}(\omega_m,\omega_m) > 0} \nonumber\\
         &-  \left.   \left[ \Re \left( \sum\limits_{m=1}^{N/2}
                     {a_m} \sqrt{  -2 F_k^{-}(\omega_m,\omega_m)}
                     \cdot \mathrm{e}^{\iu \omega_m t} \right) \right]^2 \right|_{F_{k}^{-}(\omega_m,\omega_m) < 0}
      \quad\text{for}\quad k=1,2,\ldots,6,
\label{eq:Newman}
\end{align}
where $k$ indicates the index to the load component, and $a_m$ is the complex wave amplitude for the $m$\textsuperscript{th} frequency.
Note that $F_k^\text{-}$ is the complex valued transfer function read from the WAMIT file and interpolated.  This equation is only valid for uni-directional sea states.

In evaluating the Newman approximation, it must be remembered that the purpose of it is to estimate the off-diagonal ($\omega_1 \ne \omega_2$) values from the diagonal values. If the QTF has large off diagonal components (where $\omega_m \ne \omega_n$), the results will not agree well with the full difference QTF calculations since these elements will be under estimated.

A revised form of Newman's approximation is provided by Standing \emph{et. al.} that is valid for multidirectional sea states.  For multidirectional sea states where each frequency only has on direction assocatied with it, such as with the equal energy discretization, this is equivalent to
\begin{align}
   {F_{\text{ex}~k}^{- (2)}} &\approx
            \left.   \left| \sum\limits_{m=1}^{N/2}
                     {a_m} \sqrt{   F_k^{-}(\omega_m,\omega_m)}
                     \cdot \mathrm{e}^{\iu \omega_m t} \right|^2 \right|_{F_{k}^{-}(\omega_m,\omega_m) > 0} \nonumber\\
         &-  \left.   \left| \sum\limits_{m=1}^{N/2}
                     {a_m} \sqrt{  -F_k^{-}(\omega_m,\omega_m)}
                     \cdot \mathrm{e}^{\iu \omega_m t} \right|^2 \right|_{F_{k}^{-}(\omega_m,\omega_m) < 0}
      \quad\text{for}\quad k=1,2,\ldots,6,
\label{eq:NewmanRevised}
\end{align}
This equation has been implimented as a Fourier sum rather than IFFT.  It turns out that this implimentation is exactly the same speed as doing the full DiffQTF (within 3\%).

\subsubsection{Mean drift and Newman's approximation}
The mean drift term is already included in the Newman's approximation, so there is no need to add it to the result.  This can be proven by expanding out the squares of the summations and collecting all terms where $m=n$ together.  These collected terms can be written as the mean drift term.  For this proof, it is helpful to remember that for a a given complex value, $C=a+\iu b$, we can write:
\begin{equation}
   \left(\left| C \right| \right)^2 = \left( \sqrt{a^2 + b^2} \right)^2 = a^2 + b^2 = ( a +\iu b ) ( a -\iu b ) = C\cdot C^*
\label{eq:absComplexSquared}
\end{equation}
where $C^*$ is the complex conjugate of $C$.

Taking \Cref{eq:NewmanRevised} and expanding out the terms using \Cref{eq:absComplexSquared}
\begin{align}
   {F_{\text{ex}~k}^{- (2)}} &\approx
            \left.   \left( \sum\limits_{m=1}^{N/2}
                        {a_m} \sqrt{   F_k^{-}(\omega_m,\omega_m)}
                        \cdot \mathrm{e}^{\iu \omega_m t} \right)
                     \left( \sum\limits_{m=1}^{N/2}
                        {a_m^*} \sqrt{   F_k^{-~*}(\omega_m,\omega_m)}
                        \cdot \mathrm{e}^{- \iu \omega_m t} \right)
              \right|_{F_{k}^{-}(\omega_m,\omega_m) > 0} \nonumber\\
         &-  \left.  \left( \sum\limits_{m=1}^{N/2}
                        {a_m} \sqrt{  -F_k^{-}(\omega_m,\omega_m)}
                        \cdot \mathrm{e}^{\iu \omega_m t} \right)
                     \left( \sum\limits_{m=1}^{N/2}
                        {a_m^*} \sqrt{  -F_k^{-~*}(\omega_m,\omega_m)}
                        \cdot \mathrm{e}^{- \iu \omega_m t} \right)
              \right|_{F_{k}^{-~*}(\omega_m,\omega_m) < 0}.
\label{eq:NewmanRevised2}
\end{align}
Looking at just the first term (${F_{k}^{-}(\omega_m,\omega_m) > 0}$) and remembering that $F_k^{-}(\omega_m,\omega_m) = F_k^{-~*}(\omega_m,\omega_m)$, we can expand all the crossmultiplied terms, collect the terms where $m=n$, and group the other terms where $m \ne n$.  This yields for the first term
\begin{align}
   \text{Term 1} &=  {a_1}{a_1^*} F_k^{-}(\omega_1,\omega_1) \mathrm{e}^{\iu (\omega_1 - \omega_1) t} +
                     {a_2}{a_2^*} F_k^{-}(\omega_2,\omega_2) \mathrm{e}^{\iu (\omega_2 - \omega_2) t} + \ldots \nonumber\\
                 &+  {a_{N/2}}{a_{N/2}^*} F_k^{-}(\omega_{N/2},\omega_{N/2}) \mathrm{e}^{\iu (\omega_{N/2} - \omega_{n/2}) t} \nonumber\\
                 &+  O_{m \ne n}\left(
                        \left(\sum\limits_{m=1}^{N/2}
                        {a_m} \sqrt{   F_k^{-}(\omega_m,\omega_m)}
                        \cdot \mathrm{e}^{\iu \omega_m t} \right)
                     \left( \sum\limits_{m=1}^{N/2}
                        {a_m^*} \sqrt{   F_k^{-~*}(\omega_m,\omega_m)}
                        \cdot \mathrm{e}^{- \iu \omega_m t} \right)\right) \nonumber\\
                 &= \sum\limits_{m=1}^{N/2} {a_m} {a_m^*} F_k^{-}(\omega_m,\omega_m) \nonumber\\
                 &+  O_{m \ne n}\left(
                        \left(\sum\limits_{m=1}^{N/2}
                        {a_m} \sqrt{   F_k^{-}(\omega_m,\omega_m)}
                        \cdot \mathrm{e}^{\iu \omega_m t} \right)
                     \left( \sum\limits_{m=1}^{N/2}
                        {a_m^*} \sqrt{   F_k^{-~*}(\omega_m,\omega_m)}
                        \cdot \mathrm{e}^{- \iu \omega_m t} \right)\right).
\label{eq:NewmanRevised2t1}
\end{align}
The second term is very similar to the first term.  Keeping the negative sign with the term, when expanded and multiplied together it yields
\begin{align}
   \text{Term 2} &= - {a_1}{a_1^*} (-F_k^{-}(\omega_1,\omega_1)) \mathrm{e}^{\iu (\omega_1 - \omega_1) t} +
                    - {a_2}{a_2^*} (-F_k^{-}(\omega_2,\omega_2)) \mathrm{e}^{\iu (\omega_2 - \omega_2) t} + \ldots \nonumber\\
                 &- {a_{N/2}}{a_{N/2}^*} (-F_k)^{-}(\omega_{N/2},\omega_{N/2}) \mathrm{e}^{\iu (\omega_{N/2} - \omega_{n/2}) t} \nonumber\\
                 &-  O_{m \ne n}\left(
                        \left(\sum\limits_{m=1}^{N/2}
                        {a_m} \sqrt{ - F_k^{-}(\omega_m,\omega_m)}
                        \cdot \mathrm{e}^{\iu \omega_m t} \right)
                     \left( \sum\limits_{m=1}^{N/2}
                        {a_m^*} \sqrt{ - F_k^{-~*}(\omega_m,\omega_m)}
                        \cdot \mathrm{e}^{- \iu \omega_m t} \right)\right) \nonumber\\
                 &= \sum\limits_{m=1}^{N/2} {a_m} {a_m^*} F_k^{-}(\omega_m,\omega_m) \nonumber\\
                 &+  O_{m \ne n}\left(
                        \left(\sum\limits_{m=1}^{N/2}
                        {a_m} \sqrt{ - F_k^{-}(\omega_m,\omega_m)}
                        \cdot \mathrm{e}^{\iu \omega_m t} \right)
                     \left( \sum\limits_{m=1}^{N/2}
                        {a_m^*} \sqrt{ - F_k^{-~*}(\omega_m,\omega_m)}
                        \cdot \mathrm{e}^{- \iu \omega_m t} \right)\right).
\label{eq:NewmanRevised2t2}
\end{align}
Combining the first terms from \Cref{eq:NewmanRevised2t1} and \Cref{eq:NewmanRevised2t2} where the first one contains all positive $F^-$ terms and the second contains all negative $F^-$ terms, we arrive at the equation for the mean drift given in \Cref{eq:MeanDrift}
\begin{equation}
        \left. \sum\limits_{m=1}^{N/2} {a_m} {a_m^*} F_k^{-}(\omega_m,\omega_m)\right|_{F_{k}^{-~*}(\omega_m,\omega_m) > 0}
      + \left. \sum\limits_{m=1}^{N/2} {a_m} {a_m^*} F_k^{-}(\omega_m,\omega_m)\right|_{F_{k}^{-~*}(\omega_m,\omega_m) < 0}
      =        \sum\limits_{m=1}^{N/2} {a_m} {a_m^*} F_k^{-}(\omega_m,\omega_m).
\label{eq:NewmanMnDrift}
\end{equation}

\subsubsection{Standing's equation}
Starting with \Cref{eq:NewmanRevised2}, we can substitute in for the $-F_k^- = \left| F_k^- \right|$ within the square root for when $F_{k}^{-~*}(\omega_m,\omega_m) < 0$ and $F_k^- = \left| F_k^- \right|$ within the square root for when $F_{k}^{-~*}(\omega_m,\omega_m) > 0$ to yield
\begin{align}
   {F_{\text{ex}~k}^{- (2)}} &\approx
            \left.   \left( \sum\limits_{m=1}^{N/2}
                        {a_m}    \sqrt{  \left| F_k^{-}(\omega_m,\omega_m)    \right|}
                        \cdot \mathrm{e}^{\iu \omega_m t} \right)
                     \left( \sum\limits_{m=1}^{N/2}
                        {a_m^*}  \sqrt{  \left| F_k^{-}(\omega_m,\omega_m)    \right|}
                        \cdot \mathrm{e}^{- \iu \omega_m t} \right)
              \right|_{F_{k}^{-}(\omega_m,\omega_m) > 0} \nonumber\\
         &-  \left.  \left( \sum\limits_{m=1}^{N/2}
                        {a_m}    \sqrt{  \left| F_k^{-}(\omega_m,\omega_m)    \right|}
                        \cdot \mathrm{e}^{\iu \omega_m t} \right)
                     \left( \sum\limits_{m=1}^{N/2}
                        {a_m^*}  \sqrt{  \left| F_k^{-}(\omega_m,\omega_m)    \right|}
                        \cdot \mathrm{e}^{- \iu \omega_m t} \right)
              \right|_{F_{k}^{-~*}(\omega_m,\omega_m) < 0}.
\label{eq:NewmanRevised3}
\end{align}
Now that $F_k^-$ is treated in such a way that the sign of it is not kept within the square root, we can collect the first and second term together in \Cref{eq:NewmanRevised3} by introducing the $\mathrm{sgn}$ function as
\begin{align}
   {F_{\text{ex}~k}^{- (2)}} &\approx
            \left.   \left( \sum\limits_{m=1}^{N/2} \mathrm{sgn}\left(F_k^-\right)
                        {a_m}    \sqrt{  \left| F_k^{-}(\omega_m,\omega_m)    \right|}
                        \cdot \mathrm{e}^{\iu \omega_m t} \right)
                     \left( \sum\limits_{m=1}^{N/2}
                        {a_m^*}  \sqrt{  \left| F_k^{-}(\omega_m,\omega_m)    \right|}
                        \cdot \mathrm{e}^{- \iu \omega_m t} \right)
              \right|_{F_{k}^{-}(\omega_m,\omega_m) > 0}    \nonumber\\
         &+ \left.  \left( \sum\limits_{m=1}^{N/2} \mathrm{sgn}\left(F_k^-\right)
                        {a_m}    \sqrt{  \left| F_k^{-}(\omega_m,\omega_m)    \right|}
                        \cdot \mathrm{e}^{\iu \omega_m t} \right)
                     \left( \sum\limits_{m=1}^{N/2}
                        {a_m^*}  \sqrt{  \left| F_k^{-}(\omega_m,\omega_m)    \right|}
                        \cdot \mathrm{e}^{- \iu \omega_m t} \right)
              \right|_{F_{k}^{-~*}(\omega_m,\omega_m) < 0}  \nonumber\\
         &=          \left( \sum\limits_{m=1}^{N/2} \mathrm{sgn}\left(F_k^-\right)
                        {a_m}    \sqrt{  \left| F_k^{-}(\omega_m,\omega_m)    \right|}
                        \cdot \mathrm{e}^{\iu \omega_m t} \right)
                     \left( \sum\limits_{m=1}^{N/2}
                        {a_m^*}  \sqrt{  \left| F_k^{-}(\omega_m,\omega_m)    \right|}
                        \cdot \mathrm{e}^{- \iu \omega_m t} \right)\nonumber\\
         &=          \left( \sum\limits_{m=1}^{N/2} \mathrm{sgn}\left(F_k^-\right)
                        \widetilde{a_m}    \sqrt{  \left| F_k^{-}(\omega_m,\omega_m)    \right|}
                        \cdot \mathrm{e}^{\iu \omega_m t - \phi_m} \right)
                     \left( \sum\limits_{m=1}^{N/2}
                        \widetilde{a_m}  \sqrt{  \left| F_k^{-}(\omega_m,\omega_m)    \right|}
                        \cdot \mathrm{e}^{- \iu \omega_m t + \phi_m} \right)
\label{eq:NewmanRevised4}
\end{align}
which is Standings version of the equation with $\widetilde{a_m} ~ e^{- \phi_m} = a_m$ (Standing carries the phase term of the wave amplitude within the exponential).

%\todo[inline]{add algorithm figure -- page 151 in notebook}

%\begin{figure}[ht]
%   \begin{center}
%      \beginpgfgraphicnamed{Newman.Flowchart}
%         \input{chaps/figures/Newman.Flowchart.tikz.tex}
%      \endpgfgraphicnamed
%   \end{center}
%\caption{Flow diagram for the Newman's approximation method.  $\tau$ is the period, $\omega$ is the corresponding frequency, and $\beta$ is the wave direction.  The \nth{1} and \nth{2} order {\tt WAMIT} output files are read in and arranged in ascending order within the {\tt WAMIT2\_Init} routine (\Cref{sec:WAMIT2Init}).
%   \label{fig:Newman:Flowchart}
%}
%\end{figure}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\clearpage
\subsection{Difference QTF Method}
\label{sec:2ndOrdCalc:Diff:DiffQTF}

\begin{align}
   {F_{\text{ex}~k}^{(-)(2)}} &= \Re
      \left(
         \sum\limits_{m=1}^{N/2}   a_m a_m^* F_k^{-}(\omega_m,\omega_m) +
         2 \cdot \sum\limits_{\mu^\text{-}=1}^{N/2-1} H_{\mu^\text{-}} \mathrm{e}^{\iu(\omega_{\mu^\text{-}})t}
      \right)  ,\quad&\text{for}\quad k=1,2,\ldots,6 \label{eq:DiffQTF}\\
   &\text{where}\quad
   H_{\mu^\text{-}} = \dfrac{1}{2} \sum\limits_{n=0}^{N/2-\mu^\text{-}} a_{\mu^\text{-}+n} a_n^* F_k^{-}(\omega_{\mu^\text{-}+n},\omega_n),
      \quad&\text{for}\quad 1\le\mu^\text{-}\le N-1
\label{eq:DiffQTF:H}
\end{align}

In the first term, the summation starts at $m=1$.  The value of $a_0$ is exactly 0, so it does not need to be included.

%\todo[inline]{Add algorithm figure -- p. 153 in notebook}

%\begin{figure}[ht]
%   \begin{center}
%      \beginpgfgraphicnamed{DiffQTF.Flowchart}
%         \input{chaps/figures/DiffQTF.Flowchart.tikz.tex}
%      \endpgfgraphicnamed
%   \end{center}
%\caption{Flow diagram for the full difference QTF method.  $\tau$ is the period, $\omega$ is the corresponding frequency, and $\beta$ is the wave direction.  The \nth{1} and \nth{2} order {\tt WAMIT} output files are read in and arranged in ascending order within the {\tt WAMIT2\_Init} routine (\Cref{sec:WAMIT2Init}).
%   \label{fig:DiffQTF:Flowchart}
%}
%\end{figure}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\clearpage
\section{Summation Frequency Force}
\label{sec:2ndOrdCalc:Sum}
There is only one method for calculating the second-order forces from the sum frequency.

\subsection{Summation QTF Method}
\label{sec:2ndOrdCalc:SumQTF}

\begin{align}
   {F_{\text{ex}~k}^{(+)(2)}} &= \Re
      \left(
         \sum\limits_{m=1}^{\lfloor N/4 \rfloor}   a_m a_m F_k^{+}(\omega_m,\omega_m) \mathrm{e}^{2\cdot\iu\omega_m t} +
         2 \sum\limits_{\mu^{+}=2}^{N} H_{\mu^{+}}\mathrm{e}^{\iu(\omega_{\mu^{+}-1})t}
      \right)  ,\quad\text{for}\quad k=1,2,\ldots,6 \label{eq:SumQTF}\\[1.5em]
   &\text{where}\quad\left\{
   \begin{array}{lr}
      H_{\mu^{+}} = \displaystyle\sum\limits_{n=1}^{\left\lfloor\frac{\mu^{+}-1}{2}\right\rfloor}
               a_n a_{\mu^{+}-n} F_k^{+}(\omega_n,\omega_{\mu^{+}-n}),
         \qquad\qquad&\text{for}\quad 2\le \mu^{+}\le N/2+1
            \\[1.5em]
      H_{\mu^{+}} = \displaystyle\sum\limits_{n=\mu^{+}-N}^{\left\lfloor\frac{\mu^{+}-1}{2}\right\rfloor}
               a_n a_{\mu^{+}-n} F_k^{+}(\omega_n,\omega_{\mu^{+}-n}),
         \qquad\qquad&\text{for}\quad N/2+2\le\mu^{+}\le N
   \end{array}\right.
\end{align}
where $\mu^{+} = m + n$, $\lfloor x \rfloor$ represents the floor function given by
\begin{equation*}
   \lfloor x \rfloor \equiv \max \left\{ m \in \mathbb{Z} \middle| m\le x \right\}.
\end{equation*}

In the first term of \Cref{eq:SumQTF}, the exponential term is $2\cdot \iu \omega_m t$.  This means that in populating the array that the IFFT uses for calculating the time series of this term, the frequency of the $m$\textsuperscript{th} term is $2 \cdot \omega_m$.  So in the numerical implimentation, every other frequency is populated in the frequency domain data.

The second term is an IFFT over the full range of sum frequencies from $\omega = 0$ to $\omega = 2 \omega_\text{max}$.  The IFFT contains twice as many terms as any of the IFFTs used in the other methods.  This results in a finer resolution in the resulting time series with timesteps of $1/2 \Delta t$.  While this in and of itself is not problematic, it is a problem when considering that the highest frequencies in this IFFT are above the Nyquist frequency.  The Nyquist frequency, as given in \Cref{sec:Algorithm:FFT}, is the highest frequency from the sampling theorem that is possible for a given timestep.  Any higher frequencies will be lost when we report the force time series back to the calling code (assuming we keep only every other).  So, rather than calculate the full IFFT over the extended range, we will only calculate the second term for the first $N/2$ terms up to the Nyquist frequency.  This simplifies the second term so that \Cref{eq:SumQTF} becomes
\begin{align}
   {F_{\text{ex}~k}^{(+)(2)}} &= \Re
      \left(
         \sum\limits_{m=1}^{\lfloor N/4 \rfloor}   a_m a_m F_k^{+}(\omega_m,\omega_m) \mathrm{e}^{2\cdot\iu\omega_m t} +
         2 \sum\limits_{\mu^{+}=2}^{N/2} H_{\mu^{+}}\mathrm{e}^{\iu(\omega_{\mu^{+}-1})t}
      \right)  ,\quad\text{for}\quad k=1,2,\ldots,6 \label{eq:SumQTFsimple}\\[1.5em]
   &\text{where}\quad\left\{
   \begin{array}{lr}
      H_{\mu^{+}} = \displaystyle\sum\limits_{n=1}^{\left\lfloor\frac{\mu^{+}-1}{2}\right\rfloor}
               a_n a_{\mu^{+}-n} F_k^{+}(\omega_n,\omega_{\mu^{+}-n}),
         \qquad\qquad&\text{for}\quad 2\le \mu^{+}\le N/2
   \end{array}\right.
\end{align}

%\todo[inline]{Add algorithm figure }

\endinput


\section{Throughput}
\label{sec:verification_and_benchmark:throughput}

All steps from the image classification chain and the weighting are measured.
This results in the following measurements:
\begin{itemize}
  \item Getting the raw Baumer \texttt{BayerRG8} frame
  \item Converting the color space
  \item Resizing the frame
  \item Normalizing the pixel values
  \item Running inference
  \item Applying the softmax function
  \item Weighting
\end{itemize}

To measure the time needed for each step, the Python module datetime was used.
The function \texttt{datetime.now} returns the current local date and time.

To measure the individual steps, the Python file \texttt{aionfpga.py} is slightly modified.
The initialization is not changed at all.
The infinite loop is removed, so that only one throw is captured and the application ends afterwards.
Additionally, the start and end time around each of the above steps are recorded.

The times are stored in a three-dimensional dictionary.
The first dimension contains the measured command.
The second dimension indicates whether it is the beginning or the end of the command.
Since the times vary from frame to frame, several images are acquired and averaged in a final step.
The times are appended to the end of the corresponding list.
Listing \ref{lst:measure_time} shows an example for the color transformation.

\begin{lstlisting}[style=python, caption={Measuring the required time for the color space conversion}, label=lst:measure_time]
  meas_time['Transform color']['start'].append(datetime.now())
  frames[idx] = cv2.cvtColor(raw_frame, cv2.COLOR_BayerBG2BGR)
  meas_time['Transform color']['end'].append(datetime.now())
\end{lstlisting}

The time needed for each step is the difference between end and start.
When all individual times are computed, the average value is calculated for each step.
This is printed out on the console and written to a file.
Table \ref{tab:measured_times} lists the measured times.

By calculating the reciprocal of the total time required, the frame rate can be determined:

\begin{equation}
  \text{frame rate} = \frac{1}{T_{\text{tot}}} = \frac{1}{\SI{24.329}{ms}} = \SI{41.104}{fps}
  \label{eq:achieved_framerate}
\end{equation}

\begin{table}
  \caption{Measured time for the different steps}
  \label{tab:measured_times}
  \centering
  \begin{tabular}{ll}
    \toprule
    \textbf{Step} & \textbf{Time} \\
    \midrule
    Getting the raw frame & \SI{0.233}{ms} \\
    Converting the color space & \SI{9.612}{ms} \\
    Resizing the frame & \SI{1.534}{ms} \\
    Normalizing the pixel values & \SI{4.503}{ms} \\
    Running inference & \SI{7.422}{ms} \\
    Applying the softmax function & \SI{0.458}{ms} \\
    Weighting & \SI{0.567}{ms} \\
    \midrule
    Total & \SI{24.329}{ms} \\
    \bottomrule
  \end{tabular}
\end{table}


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

\section{Symmetry breaking and phase transitions}

\marginpar{Sunday\\ 2020-7-5, \\ compiled \\ \today}

Let us consider the time, in the early universe, before BBN. The times are
\begin{figure}
\centering
\begin{tabular}{ccc}
Temperature & Symmetry group & time \\
\hline
\SI{e19}{GeV}  & \(G _{\text{GUT}}\) & \SI{e-43}{s} \\
\num{e15} \(\divisionsymbol\) \SI{e16}{GeV} & \(G _{\text{GUT}}\), barely & \SI{e-38}{s} \\
% \num{e2} \(\divisionsymbol\) \SI{e3}{GeV} & \(SU(3)_c \times SU(2)_L \times U(1)_Y\) & \num{e-10} \(\divisionsymbol\) \SI{e-12}{s} \\
\num{e2} \(\divisionsymbol\) \SI{e3}{GeV} & \(SU(3)_c \times SU(2)_L \times U(1)_Y\), barely & \num{e-10} \(\divisionsymbol\) \SI{e-12}{s} \\
\num{200} \(\divisionsymbol\) \SI{300}{MeV} & \(SU(3)_c \times U(1) _{\text{em}}\): quark-gluon confinement & \num{e-4} \(\divisionsymbol\) \SI{e-5}{s} \\
\SI{1}{MeV} & \(SU(3)_c \times U(1) _{\text{em}}\): nucleosynthesis & \SI{1}{s}
\end{tabular}
\label{tab:phase-transitions}
\caption{Phase transitions in the early universe.}
\end{figure}

The time shortly thereafter, from 1 to \SI{100}{s}, is nucleosynthesis, the earliest time we can see; we do so by exploring the abundances of light nuclei.
Everything before comes out of our model for particle physics.

After BBN, we have an epoch of radiation dominance, followed by matter dominance, then recombination, accelerated expansion.

We will not consider these, but instead keep to the first second.

The properties of the cosmic medium can either change in a \textbf{smooth crossover}, or abruptly in a \textbf{phase transition}.
Formally, the latter corresponds to an order parameter being zero in a phase and nonzero in another.

The order phase transitions describes the first derivative order which is discontinuous at them: so, first-order transitions are the sharpest, they have latent heat; while second-order transitions are smoother.

We get phase transitions when there is a mismatch between the ground state at zero temperature and at some finite temperature. Let us denote by \(\expval{\phi }_{T}\) the absolute minimum of the effective potential \(V  _{\text{eff}} (T, \phi )\).

Sometimes, the ground state being \(\phi = 0\) is restored at a finite temperature.

First-order phase transitions have a discontinuity in \(\expval{\phi }_{T}\) at a certain \(T = T_C\); for second-order phase transitions it is continuous but not differentiable.

An example of a first-order transitions is the boiling of a liquid, second-order ones are the transition of a ferromagnet, of a superconductor, of a superfluid.

For second-order and smooth-crossover transitions the medium may always be at equilibrium, on the other hand for first-order transitions switching to the other minimum becomes thermodynamically favorable if the temperature crosses the critical point: so, we can get \textbf{bubble nucleation}.

The expectation value of the field becomes inhomogeneous in space. We get bubbles with the new vacuum, for which it is energetically favorable to expand.

The transition being energetically favorable is not enough: the nucleation rate must be higher than the expansion of the universe, otherwise the transition does not complete.

\subsection{The electroweak phase transition}

The potential for the Higgs field is given by
%
\begin{align}
V(\phi ) = \mu^2 \abs{\phi }^2 + \lambda \abs{\phi }^{4}
\,,
\end{align}
%
with \(\mu^2<0\) and \(\lambda >0\). Then, the VEV is
%
\begin{align}
\expval{\phi }_0 = \sqrt{\frac{- \mu^2}{2 \lambda }} = \frac{v}{\sqrt{2}}
\,,
\end{align}
%
so at zero temperature the potential can be written as
%
\begin{align}
V(\phi) = \lambda \qty(\phi^2 - \frac{v^2}{2})^2
\,.
\end{align}

What do we write for a nonzero temperature? The term to add is:
%
\begin{align}
V &= V(T = 0) + \frac{T^2}{24} \qty[ \sum _{\text{bosons}} g_i m_i^2 (\phi ) + \frac{1}{2} \sum _{\text{fermions}} g_i m_i^2 (\phi )]  \\
&= \qty(- \lambda v^2 + \frac{\alpha}{24} T^2) \phi  + \lambda \phi^{4}
\,,
\end{align}
%
where \(m_i (\phi ) = h_i \phi \), \(h_i\) being the coupling constant of that specific fermion or boson to \(\phi \).
The sum over the bosons runs over the Higgs itself as well: so, we get a term \(g_h h_h^2 H^2\) as well.
Finally, we defined
%
\begin{align}
\alpha = \sum _{\text{bosons}} g_i h_i^2 (\phi ) + \frac{1}{2} \sum _{\text{fermions}} g_i h_i^2 (\phi )
\,.
\end{align}

So, we can see that when the coefficient of \(\phi^2\) becomes larger than \(0\) the transition takes place: this will happen at \(\alpha T^2 / 24 = \lambda v^2\), which means
%
\begin{align}
T_C = 2 v \sqrt{ \frac{6\lambda}{\alpha }}
= 2 \sqrt{ \frac{M_H^2}{4 M_W^2 + 2 M_Z^2 + 4 m_t^2 + M_H^2}} v
\approx \SI{146}{GeV}
\,.
\end{align}

This is a tree-level perturbative result: if we account for nonperturbative effects we find \(T_C \approx \SI{160}{GeV}\).

If we were to use the perturbative approach (at one loop) we would find that the electroweak phase transition is of first order, however using a nonperturbative one we get that it is smoother.
Perturbing would work for small \( M_H / M_W \), but actually this is larger than 1.

Working nonperturbatively, one finds that the transition is of second order or even smoother.

\subsubsection{Phase transitions and inflation}

\todo[inline]{Graph of \(V(\phi )\) with a bump, a slow decrease region, and then an absolute minimum: where does this shape come from?}

At the GUT temperature, the average energy of the Higgs field is around the GUT energy scale.
After the temperature goes below this, the GUT symmetry is broken.

The scale factor scales like \(H \sim T^2 / M_P^{*}\), where \(M_P^{*} \approx M_P / \sqrt{g_{*}} \approx \SI{e18}{GeV}\).
Then, if we take \(M _{\text{GUT}} \sim \SI{e16}{GeV}\) we get
%
\begin{align}
t = H^{-1} = \frac{\num{e2}}{M _{\text{GUT}}}
\,.
\end{align}

The vacuum energy density will be given by the potential at \(\phi  = 0\). In this dark energy dominated period, the scale factor will scale like \(a \sim e^{Ht}\).

The energy of this false vacuum is much larger than the one of the true vacuum.

If the time it takes for \(\phi \) to evolve from 0 to \(v\) is of the order \(t \sim 100 H^{-1}\), then initial smooth patches whose size is comparable to \(H^{-1} \sim \SI{e-28}{cm}\) will be blown out by \(e^{H t} = e^{100}\): they will become of a size \SI{3e15}{cm}, or about \SI{200}{AU}.

The entropy increase is enormous: we can compute it like \(S = T_C^3 / H^3\).
This is because the entropy density \(s\) scales like \(T^3\) \cite[eq.\ 8.46]{bergstromCosmologyParticleAstrophysics2003}, and we retrieve the total entropy by multiplying by \(V \sim a^{3}\).

\todo[inline]{Hold on, the volume is \(a^3\), not \(H^{-3}\)! In a steady-state solution \(H\) is constant. The reasoning works out, since it is \(t\) which scales by 100, but what he wrote is incorrect\dots}

So, even if the transition does not correspond to a temperature change, the variation in temperature is \(\qty( e^{Ht})^3 \sim \num{e130}\), since \(t\) is multiplied by 100.

Some early models of slow-roll inflation are based on a transition between \(SU(5)\) to the SM symmetries.

The idea is to get a GUT potential which is very close to flat near the origin, so that the quadratic term \(m^2\phi^2\) vanishes.

This way, we have no SSB in the tree-level GUT Higgs potential (since the self-interaction terms are only relevant at higher powers of \(\phi  \)).
The only corrections are \emph{loop} corrections, possibly with loops constituted by \(SU(5) \) gauge bosons.

\subsubsection{Coleman-Weinberg mechanism}

We take
%
\begin{align}
V(\phi ) = \const \times \phi^{4} \qty[\log \qty( \frac{\phi^2}{v^2}) - \frac{1}{2}] + \const \times v^4
\,,
\end{align}
%
where \(v = \expval{\phi } \sim \SI{e16}{GeV}\).

If \(\phi \ll v\), the potential looks like \(V \sim v^{4} - \lambda \phi^{4} / 4\), where \(\lambda = \const \log (\phi^2 / v^2) - 1/2 \sim \num{e-1} \divisionsymbol \num{e-2}\).

If \(\phi \) is close to 0, then, the potential is approximated up to third order as
%
\begin{align}
V(\phi ) \sim \alpha^2 _{\text{GUT}} \frac{v^{4}}{2}
\,,
\end{align}
%
where \(\alpha^2 _{\text{GUT}} \sim \num{e-3}\).
\todo[inline]{Should \(\alpha^2 \) not be related to \(\lambda \)? Also, I do not understand the characterization of the situations: how is \(\phi \ll v\) different from \(\phi \sim 0\)? }

In this model, the expansion rate is given by
%
\begin{align}
H^2 \approx \frac{4 \pi }{3} \frac{\const v^{4}}{M_P^2} \approx \qty( \SI{e11}{GeV})^2
\,.
\end{align}

With this model we get a phase transition which is first order at \(T_C \sim \SI{e16}{GeV}\).
There are, however, issues with this model.

\todo[inline]{What can we say about this model?}

\section{Cosmic matter-antimatter asymmetry}

The matter-antimatter asymmetry problem is two-fold:
\begin{enumerate}
    \item we want to find a way to generate a nonzero baryon number \(\Delta B = n_B - n_{\overline{B}}\) starting from a symmetric \(\Delta B = 0\) universe;
    \item we want to account for the smallness of the baryon-to-photon ratio:
    %
    \begin{align}
    \eta_{B} = \frac{n_{B, 0}}{n_{\gamma , 0}} \approx \num{6e-10}
    \,.
    \end{align}
\end{enumerate}

We can express the latter using
%
\begin{align}
\Delta B = \frac{n_B - n_{\overline{B}}}{s} \approx \num{9e-11}
\,,
\end{align}
%
the baryon-to-entropy ratio.

If we had \(\Delta B = 0\), the fraction of the matter density in the universe which is represented by baryons would be very much smaller than \SI{5}{\percent}.

So far, there is no experimental evidence for large antimatter regions.
If it existed, it would have to be separated from regular matter by extremely large distances, since otherwise we would detect a gamma-ray background from the common annihilation.

\subsection{Sakharov's conditions}

They are necessary conditions for the creation of baryon asymmetry starting from a baryon-symmetric situation.
They are:
\begin{enumerate}
    \item Baryon number non-conservation;
    \item \(C\) and \(CP\) violation;
    \item out-of-equilibrium processes.
\end{enumerate}

The first condition arises because if all processes conserved baryon number then there could be no formation of asymmetry.
The second condition arises because if there was charge-conjugation symmetry then processes generating matter and antimatter would have the exact same properties, and would therefore statistically occur in the same amounts.
Out-of-equilibrium processes are needed since otherwise, because of \(CPT\) symmetry, \(\Delta B\) increasing and decreasing processes would occur in the same amounts.

\subsubsection{Baryogenesis in a GUT}

Let us suppose that there is a GUT scalar particle \(X\) which has two decay channels, either \(qq\) or \(\overline{q} \overline{\ell}\), where \(q\) is a quark and \(\ell\) is a lepton.

These are both \(B\)-violating, the first introduces \(B = +2/3\) and the second introduces \(B = - 1/3\).
Let us suppose that the branching ratios are \(\tau \) and \(1 - \tau \) respectively.

The antiparticle \(\overline{X}\) can decay into \(\overline{q} \overline{q}\) or \(q \ell\), which have \(B = - 2/3\) and \(B = + 1/3\) and branching ratios \(\overline{\tau}\) and \(1 - \overline{\tau}\) respectively.

If there is \(C\) violation, we can have \(\tau \neq \overline{\tau}\).
So, if we have a \(X \overline{X}\) pair, and both of the particles decay, then the changes of baryon number are \( \tau - 1/3\) and \(- \overline{\tau} + 1/3\) respectively, so in total we find \(\Delta B_{X \overline{X}} = \tau - \overline{\tau}\).

This yields baryon number violation by violating the first two Sakharov conditions: where does the third one come in?

Let us again consider the boson \(X\), a ``leptoquark'' gauge boson which is coupled to all fermions. Its coupling constant will be \(\alpha = \alpha _{\text{GUT}}\).
Its SM charges can either be \((3, 2, +4/3)\) or \((3,2, + 1/3)\).

The decay rate of \(X\) into fermions will be given by \(\Gamma^{X}_{D} \approx \alpha M_X\).
The decay of \(X\) can occur as long as \(\Gamma^{X}_{D} \geq H \sim
 T^2 / M_P^{*}\), so that on average a particle has good odds to have actually managed to decay since the beginning of the universe.

This condition can be written as \(T^2< \alpha M_X M^{*}_{P}\), and if we consider the time at which \(T = M_X\) it becomes \(M_X < \alpha M_P^{*}\).
The condition of this \(X\) being able to decay means that it can reach equilibrium: so, at \(T = M_X\) equilibrium can be achieved as long as \(X\) is less massive than \(\alpha \times \SI{e18}{GeV}\).

If this condition is fulfilled, then as \(T\) drops below \(M_X\) the particle \(X\) is still in equilibrium and the \(B\) violating processes are still happening. So, as this happens, all the \(B\) violation is erased.
\todo[inline]{Wait, how?}

If, on the other hand, \(M_X \geq \alpha \SI{e18}{GeV}\), the lifetime of \(X\) is longer than the age of the universe when the temperature reaches its mass.
Therefore, it only starts decaying \emph{later}, when \(T < M_X\), and these decays are occurring out of equilibrium.

The ratio \(n_X / n_\gamma \) is approximately 1, but the density of \(X\) is far from the equilibrium one, which would satisfy
%
\begin{align}
n_X^{\text{eq}} \sim (M_X T)^{3/2} e^{-M_X / T}
\,,
\end{align}
%
and since \(M_X > T\) this would be suppressed, and we'd have \(n_X^{\text{eq}} \ll n_\gamma \).
Intuitively, if we \emph{did} have equilibrium almost all the \(X\)s would have decayed earlier, many more of them are left than this.

So, the net \(\Delta B \neq 0\) cannot be erased. If we define \(\Delta B = \tau - \overline{\tau}\), then we will be left with a number density of baryons
%
\begin{align}
n_B = \Delta B n_X
\,
\end{align}
%
at the time when \(T = M_X\). Since \(n_X \sim n_\gamma \), we also have \(n_B \approx \Delta B n_\gamma \).

At this point, \(\Delta B\) is frozen
\todo[inline]{Is it? Many \(X\)s still have to decay, and when they do they violate \(B\)!}
however \(n_\gamma \) is not conserved in later stages of the evolution --- for example, when electron-positron annihilation happens ---, so we cannot rely on the ratio \(n_B / n_\gamma \) to be constant.

Instead, we can use the specific entropy ratio \(n_B / s\), where \cite[eqs.\ 8.46 and 8.49]{bergstromCosmologyParticleAstrophysics2003}
%
\begin{align}
s = \frac{2 \pi^2}{45} g_s (T) T^3
= \frac{\pi^{4}}{45 \zeta (3)} g_s (T) n_\gamma
\,,
\end{align}
%
where, at \(T \sim M_X\), we have \(g_s (T) \sim 100\), so this means \(s \sim 100 n_\gamma \).

Note that this \(g_s(T)\) is not the same as the \(g(T)\) we get when computing the density, although they are close in value \cite[fig.\ 1]{husdalEffectiveDegreesFreedom2016}.
For an in-depth review of how they are defined, refer to Husdal \cite[sec.\ 4.5]{husdalEffectiveDegreesFreedom2016}; the gist is that thermodynamic quantities have different dependencies on the phase space density and the temperature, so when we weigh the various particles we must account for these differences. The \(g_s\) describes the effective degrees of freedom associated with the computation of the entropy, while \(g\) refers to the degrees of freedom associated with the energy density.

Therefore,
%
\begin{align}
\frac{n_B}{s} \sim \frac{\Delta B}{100}
\,.
\end{align}

From Big Bang Nucleosynthesis we can place a bound on \(\eta  = n_B / n_\gamma \), namely \(\num{5e-10} < \eta < \num{7e-10}\).

The same reasoning can be applied today: now we have \(g_s(T) \approx 4\), so we find \(s \approx 7 n_\gamma \).
Then, using the same bound from BBN we get
%
\begin{align}
\num{7e-11} <
\frac{n_B}{s}
< \num{e-10}
\,.
\end{align}

\todo[inline]{And this is incompatible with the earlier one\dots which should we use?}

Now, since \(n_B / s \approx \num{e-2} \Delta B\) we get that we can have \(\tau - \overline{\tau} \sim \num{e-8}\) to explain observations.

In order to have \(\tau \neq \overline{\tau}\) we need \(B\), \(C\) and \(CP\) violation.
However, even if these symmetries are violated, at tree level the decay rates for \(\Gamma (X \to qq)\) and \(\Gamma (\overline{X} \to \overline{q} \overline{q})\) are equal: all the kinematics is the same, and we will get
%
\begin{align}
\Gamma (X \to qq) \propto \abs{g}^2 M_X
\qquad \text{and} \qquad
\Gamma (\overline{X} \to \overline{q} \overline{q}) \propto \abs{g^{*}}^2 M_X
\,,
\end{align}
%
so they will be equal!
This can change if we consider loops.

\begin{claim}
Say \(I\) is the complex-valued loop integral, and we assume that a particle \(Y\) propagates between the quarks with a coupling \(g'\).
Then, the result reads:
%
\begin{align}
\tau - \overline{\tau} = \frac{2 \Im I \Im \qty(g_2 g_1^{*} g_1' g^{\prime *}_2)}{\abs{g_1 }^2 + \abs{g_2 }^2}
\approx \frac{g^2}{4 \pi } f \qty( \frac{m_X}{m_Y})
\,,
\end{align}
%
where \(f\) is a function such that \(f(1) = 0\), and which is of order 1 for large arguments.
\end{claim}

Since we want \(\tau - \overline{\tau} \lesssim g^2 / 4 \pi \), we must have \(g^2 / 4 \pi \gtrsim \num{e-8}\).

This allows us to specify our out-of-equilibrium condition better: it was \(M_X \gtrsim \alpha M_P^{*}\), but with the new bound on \(\alpha \) we can write it as
%
\begin{align}
M_X > \SI{e10}{GeV}
\,.
\end{align}

So, \(X\) must be a superheavy particle.
In order to implement this baryogenesis process the reheating temperature must be quite high, \(T _{\text{RH}} > \SI{e10}{GeV}\).

Is \(\Delta B\) preserved after the breaking of \(G _{\text{GUT}}\)? If, under the SM symmetries, \(B\) is conserved we should have no issue.
This, as we shall see, might not be the case.

\todo[inline]{Hold up: if the decay channel of the superheavy \(X\) are \(B\)-breaking, what does the temperature have to do with it? If there are \(X\)s leftover they still need to decay\dots}

\end{document}


\chapter{System design and implementation}
\label{chapter:system-design}

This chapter presents the entire work of the author. The work is split into three parts in the attempt to combine deep neural networks with Q-Learning. The game chosen for the  experiment is the Tower of Hanoi due to its simplicity and also, due to the static environment. Afterwards, the values obtained through Q-Learning have been used to train a deep convolution network combined with the generated frames. Finally, our attempt is to combine the Q-learning algorithm with convolution networks.

\section{Q-Learning}
\label{sec:ql}
In this section we attempt to find the optimal policy for playing the Tower of Hanoi game. The algorithm starts with a pool of actions initialized with {UP, DOWN, LEFT, RIGHT} and a table Q containing the values for every (state,action) pair.

The discount factor $\gamma$ is set to 0.95, the future rewards being taken into account when updating the action-value function. The learning rate $\alpha$ is chosen at 0.1, thus the algorithm can converge to an optimal policy.

The exploration vs. exploitation problem is solved by using a variable $\epsilon$ which is initialized with 1 (1 is used when choosing only random actions and 0 when the action that can maximize the score is chosen). In order to make the current policy converge to the optimal policy the number of iterations used is set to 11 and the number of episodes per iteration set to 1000. After each iteration is finished, $\epsilon$ it is decreased with 0.1 until it will take the value 0. This method has been used to let the agent explore using random actions in the first iteration, afterwards exploiting the values learned in the last iterations.

After all the iterations are finished, the algorithm generates a dataset. For each value stored in Q-table, it generates the frame from each coded state.

On the next page, a pseudocode of Q-Learning is presented, which is an adaptation after the algorithm found in Norvig's book{\cite{norvig}}. The algorithm tries to estimate an optimal action-value function using the $\epsilon$-greedy policy, more exactly, it chooses a random action with probability $\epsilon$ and chooses the optimum action with probability 1-$\epsilon$.
\newpage
\begin{algorithm}
	\floatname{algorithm}{Algorithm}
	\caption{Q-Network} \label{alg-code}
	\begin{algorithmic}[1]
		\State set size of Q to with no_states x no_action and initialize it
		\State choose $\epsilon$ between (0,1)
		\State let \textbf{s} be the current state of the game
		\State let \textbf{actions} be a pool with {$a_1$,$a_2$,...,$a_n$}
		\While{game not over}
			\State r = random number between (0,1)
			\If{r < $\epsilon$}
				\State $a_t$ = random action
			\Else
				\State $a_t$ = $argmax_a$ Q(s, a)
			\EndIf

			\State $s^\prime$, r = apply_action(a, s)
			\State Q(s,a) = Q(s,a) + $\alpha\cdot$(r + $\gamma\cdot \max_a Q(s^\prime,a^\prime)-Q(s,a)$)
		\EndWhile
	\end{algorithmic}
\end{algorithm}

\section{Convolutional Neural Networks}
This section comes with an attempt to discuss various architecture models that could be suitable for our problem. To see if the network fits the main theme of this paper, one must provide proof that the network model can be generalized and is not hitting the ``high variance problem''. In order to come with a scientific proof or at least an empirical one, several experiments have been made.

\subsection{Regression with deep-learning and complex model}
The model proposed by Yann Lecun et al.\cite{energy-based} was slightly modified in order to map our problem. For the purpose of keeping things clear and well-separated every discussion about a network should be split into the next subjects: preprocessing data, chosen model for the network, loss function, training and testing.

For the first attempt, a model used in face detection and pose estimation has been chosen because good results in learning features relevant for object recognition have been promised. Also, it is possible for this model to be applied over large images.

\subsubsection{Data}

In this section \ref{sec:ql}, we generated a dataset of 160 images with 4 labels for each one (Tower of Hanoi has 160 states and offers 4 possible actions). In this section we try to build a convolutional neural network capable of predicting those values from images. This is made for the sake of bringing strong proof that our network model is capable of learning features from the dataset and not leading, instead, to a ``dead'' network which is ``overlearning'' and cannot be used on new samples.

First step was to resolve the problem of the small number of samples (160) from the dataset. This has been solved by generating 64 other datasets (to achieve approximately 10,000 samples) from the original one with noise added or color changed. In this way we can ensure that the network is capable of learning features dependent on size in this case.

The next figure(\ref{fig:155}) represents a state of the game and the next ones(\ref{fig:states}) represent altered images with noise added and color changed.

\begin{figure}[h]
	\begin{center}
		\frame{\includegraphics[width=130px,height=130px]{src/img/system-design/155}}
		\caption{Initial state of the game ``Tower of Hanoi''} \label{fig:155}
    \end{center}
\end{figure}

\begin{figure}[h]
	\begin{center}
		\frame{\includegraphics[width=253px,height=126px]{src/img/system-design/states}}
		\caption{Altered dataset} \label{fig:states}
    \end{center}
\end{figure}

For the preprocessing data various problems have been encountered. First of all, there is a large discussion on the RGB vs. YUV topic. This paper implements the YUV transformation based on the assumption that luminance should be separated from chrominance. If features dependent on color should be learned, then the neurons connected with the chrominance pixels will be activated, otherwise the neurons connected with luminance pixels will be activated. Both types of channels are kept in the attempt to make an algorithm that could make a better generalization.  Also, the YUV color is much closer to the human vision than RGB.

The decision not to work with the 1-channel colors spaces such as grayscale is well-founded. There are games where size should not be a feature to be learned and in this cases we are interested in learning features dependent on color.

The next step was to normalize the images for aligning the range of pixel intensity values to a normal distribution. In other words, the histogram of the images are stretched and the contrast is improved in order to get sharp edges.

The normalization of the images implies computing the mean and the standard deviation. These values are computed for the training dataset of each channel. Then, we add the mean and divide it by standard deviation. This operation is applied on each channel from both datasets (train and test).

Another way to improve the contrast is using a gaussian matrix which follows a gaussian distribution, as it is clear from its name. The gaussian distribution states that average things should occur frequently and extreme things should occur rarely. The gaussian matrix will slide all over the image and will modify the pixel values such that the pixels from the middle of the neighbourhood will be more important than the pixel values from the edge of the gaussian matrix. If the edge pixel values have a zero importance than the resulting image will be identical to the initial image.

On the other hand, labels also need to be processed. Because of the formula for estimating the action-value function (Q) different ranges of values were generated. For example, if we have to do regression on values as 0,..., 100 there would not be a problem because the delta range is $10^2$, but the values generated follow a delta range of $10^5$. This can cause instability in the network. These being said, the paper proposes to bring the values to the same range using a logarithmic function and of course, to normalize them to follow the normal distribution.

Data was also shuffled to avoid having consecutive states of the game.

\subsubsection{Model}

The model used for training the convolutional neural network is the model presented in the next paper: ``Synergistic Face Detection and Pose Estimation with Energy-Based Models''\cite{energy-based} with some modifications such that the model becomes suitable for our network.

The model follows another model called LeNet-5 proposed by Yann LeCun et al. which was used in document recognition\cite{basedlearning} for training a network that could recognize noisy handwritten characters. The results obtained by the network state that the error rate is small, under 1$\%$ which is extremely satisfying. Trained on noisy handwritten characters draws attention to one important aspect: if the model is capable of generalizing even in heavy conditions, why could it not be used in combination with Q-learning for playing games.

In the next figure(\ref{fig:myarch}) we can see how the network suggested in this article looks.

\begin{figure}[h]
	\begin{center}
		\includegraphics[width=410px,height=87px]{src/img/system-design/myarch}
		\caption{ConvNet Architecture} \label{fig:myarch}
    \end{center}
\end{figure}

The network is composed of three layers. Each layer applies kernel convolutions and samples on the data. After each layer we use the hyperbolic tangent as the layer activation function. As discussed in the paper ``Efficient Backprop'' by Yann LeCun et al., the motivation for using the hyperbolic tanh is similar to the one of normalizing data. The mean of the output data tends to be closer to zero, thus it is less likely to cause instabilities in the network derivatives when used in combination with back-propagation.

After the final layer, the sigmoid activation function has been used because the labels are normalized by scaling between 0 and 1.

The input layer consists of no_features x no_pixels_width x no_pixels_height neurons and the output layer has 4 neurons because only 4 actions are needed to play Tower of Hanoi.

The last layers are fully connected and for hidden layers the Spatial Convolution and Sub Sampling have been used. In the appendix \ref{appendix:model} the implementation in Torch7 can be found.

\subsubsection{Loss function}
For computing the error, Mean Squared Error was used. Being a task of regression, and not a task of classification the MSE is most appropriate for use.
\begin{equation}
loss(target,output) = \frac{1}{no_{samples}}\cdot\displaystyle\sum_{i=1}^{no_{samples}}\cdot((output^{(i)}) - target^{(i)})^2
\end{equation}

\subsection{Classification with deep-learning and complex model}

Because the last results for doing regression with convolutional networks did not match the author's expectations, another option have been provided. What if we try to learn the same results using a clasificator? All in all, we try to predict the action for every state.

Firstly, we change the architecture from LeNet-5 with the one used for training on Google Street View House Numbers proposed by Yuval Netzer et al. in the ``Reading Digits in Natural Images with Unsupervised Feature Learning''\cite{svhn} paper. The dataset used by them is very similar with the MNIST database (Yann Lecun)\footnote{\url{http://yann.lecun.com/exdb/mnist/}} except for the fact, that SVHN\footnote{\url{http://ufldl.stanford.edu/housenumbers/}} provides natural scene images.

\subsubsection{Data}
For predicting classes we need to transform continuous values to labels and for each state of the dataset we choose the label (\'up\' = 1, \'down\' = 2, \'left\' = 3, \'right\' = 4) according the maximum value. If the value corresponding to the \`up\`-action is the biggest, then we choose label 1.
Like the previous model architecture, the data is converted from RGB to YUV color space, to separate the luminance from chrominance. After this step they perform contrast normalization to sharpen edges and also, the normalization is performed.

\subsubsection{Model}
The model proposed for training the network is slightly different the the other one. The input remains the same, 3 channels and 32x32 size. The output is formed by four neurons corresponding for each action. The hidden layer activation functions used for the model is also tanh. The network is composed by two convolution layer and two pooling layers.

\subsubsection{Loss function}
For computing the error, Log Soft Max was used. Being a task of classification, and not a task of regression we need our network to map categorical information (discrete values variables) on continuous normalized data.

\begin{equation}
loss(x^{(i)}) = \log {\frac{1}{\displaystyle\sum_{j} e^{x^{(j)}}\cdot e^{x^{(i)}}}}
\end{equation}

\subsection{Regression with deep-learning and simple model}

Both of the last experiments using convolutional neural networks did not lead to satisfactory results and that is the reason we propose another model. We found that sometimes RGB may lead to better improvements than YUV\cite{pipeline} so we passed the images to CNN into RGB color-space. Another preprocessing step was removing contrast normalization because it does not improve the results, leading to overfitting. The new model comes with two convolutions and two poolings. The output activation functions remain the same, tanh for hidden layers and sigmoid for the output layers in order to predict the values from Q-Learning which are between 0 and 1. We removed one fully connected layer and let 150 neurons on the last hidden layers. An implementation in Torch7 can be found in appendix \ref{appendix:good-model}.

\subsection{Q-Network}

In this section we discuss the implementation for Q-Network adapted to our needs. In the \ref{fig:qmodel} is given a graphical representation of the whole model. The experiment was done on Tower of Hanoi games as the other experiments were done. On the preprocessing step the image were rescaled to 32x32 and the input given to the Q-Network is keeping the RGB color space. For the model we used the simple model discussed in the last section. This time we started with two networks: the action-value network Q and the action-value target network $Q^-$. The loss function is the same, MSE.

Then, we train the network as it follows: we start with a $\epsilon$-probability of 100\% in choosing a random action and 0\% for choosing the best action. After every 9 episodes we update the $\epsilon$-probability by decreasing it with 10\%. After we choose the action we observe the new state and the reward. We give the new sample to the $Q^-$ network and update the output corresponding to the action we have made with the reward if the episode had finished or with the q-learning equations. We compute the loss between Q and $Q^-$ and propagate loss derivative through Q. Every 100 steps we update the weights of $Q^-$ with the ones of Q.

\begin{figure}[h]
	\begin{center}
		\frame{\includegraphics[width=321px,height=210px]{src/img/system-design/qmodel}}
		\caption{Q-Network} \label{fig:qmodel}
    \end{center}
\end{figure}


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

\section{Physics of compact objects in GR and beyond}

\marginpar{Monday\\ 2021-2-1, \\ compiled \\ \today}

Lecture by Gualtieri from Milan Bicocca.
We will use geometrized units \(G = c = 1\) (note that this is not the same as the particle-physics \(c = \hbar = 1\)).

References: Misner-Thorne-Wheeler, Weinberg, Poisson-Will (``Gravity''), Wald (``GR''), Chandrasekhar (``The mathematical theory of BH''), Ferrari-Gualtieri.

The compactness in general is defined to be \(C = M / R\), and we ask that it is \(\lesssim 1\) in order to be discussing a compact object.
The known compact objects are neutron stars (possibly quark stars) and black holes.
Exotic compact objects are also a possibility.

Observables for black holes include:
\begin{enumerate}
    \item Accretion disks: EM emission, mostly in the X-ray range;
    \item BH shadow: EM emission;
    \item motion of stars around supermassive BH;
    \item BBH coalescence: GW emission, ground-based detection for small (\(5 \divisionsymbol 100 M_{\odot}\)) BHs, space-based detection for massive (\(\num{e6} \divisionsymbol \num{e7} M_{\odot}\)) BHs;
    \item stochastic background.
\end{enumerate}

For NSs we have
\begin{enumerate}
    \item accretion disks;
    \item binary pulsars: EM emisssion (radio);
    \item BNS coalescence with ground-based GW detectors;
    \item pulsars as sources of continuous GWs.
\end{enumerate}

We consider a \textbf{stationary, isolated} body in GR.
``Isolated'' means that the spatial support of its stress-energy tensor \(T_{\mu \nu }\) is limited: it is inside a world-tube.
The spacetime will be \emph{asymptotically flat}: a rather informal definition is the existence of a coordinate \(r\) such that
%
\begin{align}
\lim_{r \to \infty } g_{\mu \nu } = \eta_{\mu \nu }
\,.
\end{align}

If \(R\) is the scale of the support of the stress-energy tensor, then we know that \(r \gg R\) is the far-field region, in which the field is \emph{weak}: \(g_{\mu \nu } = \eta_{\mu \nu } + h_{\mu \nu }\), with \(\abs{h_{\mu \nu }} \ll 1 \) and \(\abs{h_{\mu \nu , \rho } \ll 1/R}\).
In general, we will expand in orders of \(1/R\).

It can be shown that it is always possible to write the far-field metric in the form
%
\begin{align}
\dd{s^2} = - \qty(1 - \frac{2M}{r}) \dd{t^2}
+ \qty(1 + \frac{2M}{r}) \dd{r^2} + r^2 \qty( \dd{\theta^2} + \sin^2 \theta \dd{\varphi^2}) - \frac{4 J }{r} \sin^2 \theta \dd{\theta } \dd{\varphi } + \order{ \qty( \frac{1}{r})^2}
\,.
\end{align}

In the weak field limit we have, in terms of the trace-reversed \(\overline{h}_{\mu \nu } = h_{\mu \nu } - (1/2) \eta_{\mu \nu }\):
%
\begin{align}
\square_b \overline{h}_{\mu \nu } = - 16 \pi G_{\mu \nu }
\,,
\end{align}
%
and we can calculate this trace-reversed metric perturbation by integrating:
%
\begin{align}
\overline{h}_{\mu \nu } (x) = 4 \int_{V} \frac{T_{\mu \nu } (x') \dd[4]{x'}}{\abs{\vec{x} - \vec{x}'}}
\,.
\end{align}

This integral can be approximated through the multipole expansion:
%
\begin{align}
\frac{1}{\abs{\vec{x} - \vec{x}'}} = \frac{1}{r} + \frac{\vec{x} \cdot \vec{x}^{\prime}}{r^2} + \order{r^{-3}}
\,,
\end{align}
%
so the metric perturbation will read
%
\begin{align}
\overline{h}_{\mu \nu } = \frac{4}{r} \int_{V} T_{\mu \nu } \dd[3]{x}
+ \frac{4}{r^2} \vec{x} \cdot
\int_{V} T_{\mu \nu } \vec{x}' \dd[3]{x}
+ \dots
\,,
\end{align}
%
but this last term is just the angular momentum of the object.

In the end one finds
%
\begin{align}
h_{00} &= \frac{2M}{r} + \order{r^{-3}}  \\
h_{0i} &= \frac{2}{r^2} \epsilon_{ijk} x^{j} J^{k} + \order{r^{-3}}  \\
h_{ij} &= \frac{2M}{r} \delta_{ij} + \order{r^{-3}}
\,.
\end{align}

The metric is then the one we wrote as long as \(\vec{J} = (0, 0, J)\).

In the strong-field limit we cannot use Newtonian integrals, however we can write the equation \(\tensor{\overline{h}}{^{\mu }_{\nu , \mu} } = 0\). It turns out that the solution is the same, but \(M\) and \(J\) do not necessarily correspond to the mass and angular momentum.

We can define a stress-energy \emph{pseudotensor} such that
%
\begin{align}
(-g) \qty(T^{\mu \nu } + t^{\mu \nu }) = \frac{1}{16} \fdv{}{x^{\mu } } \fdv{}{x^{\nu }} \qty(g^{\mu \nu } g^{\nu \rho } - g^{\mu })
\,,
\end{align}
%
\todo[inline]{Fix equation, unreadable}

The pseudo-momentum
%
\begin{align}
P^{\mu } = \int \dd[3]{x} (-g) \qty(T^{\mu \nu } + t^{\mu \nu })
\,.
\end{align}

The expression for the pseudo-stress-energy tensor is a total divergence, so we can perform the integration on the boundary. We then find \(P^{0}= M\) and \(J = \epsilon_{ijk} \int \dd[3]{x} (-g) x^{i} \qty(T + t)\).
\todo[inline]{Still unintelligible.}

We can measure the mass from Kepler's laws, seeing the stars orbiting around the object.
The angular momentum can be measured by looking at the precession of a gyroscope orbiting around the central body.

The angular momentum is described by the intrinsic spin \(S^{\mu }\), which satisfies \(u^{\alpha } S_{\alpha } = 0\) and evolves according to the equation \(u^{\alpha } S^{\mu }_{; \alpha } = 0\): this means
%
\begin{align}
\dv{S^{i}}{\tau } = \epsilon_{ijk} \omega ^{j} S^{k}
\,,
\end{align}
%
where \(\omega^{k} = (1/2) \epsilon^{kij} h_{0i,j}\).
The expression depends on the metric perturbation: we have precession with angular velocity
%
\begin{align}
\vec{\omega} = \frac{1}{r} \qty(- \vec{J} + 3\frac{\vec{J} \cdot \vec{x}}{r^2} \vec{x})
\,.
\end{align}

So far we have not measured the spin of a compact object in this manner, but we have managed to do it with the Earth.

The multipoles can be approximated as constant for a compact objects.
In Newtoninan gravity we have
%
\begin{align}
\nabla^2 \phi = 4 \pi \rho
\,,
\end{align}
%
and we can write the field solution of this equation as
%
\begin{align}
\phi (\vec{x}) &= \sum_{\ell, m} \frac{1}{r^{\ell + 1}} \frac{4 \pi }{2 \ell + 1} I_{\ell m} Y_{\ell m} (\theta , \varphi )   \\
&= \sum _{\ell = 0}^{\infty } \frac{1}{r^{\ell+1}} \frac{(2 \ell-1)!!}{\ell!} I^{<i_1 \dots i_\ell>} n^{<i_1} \dots n^{i_\ell>}
\,,
\end{align}
%
where
%
\begin{align}
I_{\ell m} (t) = \int \rho (t, \vec{x}) r^{\ell} Y_{\ell m} (\theta , \varphi ) \dd[3]{x}
\,.
\end{align}

The angular parentheses mean symmetrization without trace: for example,
%
\begin{align}
n^{<i} n^{j>} = n^{i} n^{j} - \frac{1}{3} \delta^{ij}
\,.
\end{align}

These are the Symmetric Trace-Free moments.
The quadrupole moment is just the \(\ell=2\) term in this expansion:
%
\begin{align}
Q^{ij} = I^{ij} = \int \rho (t, \vec{x}) \qty(x^{i} x^{j} - \frac{1}{3} \delta^{ij}) \dd[3]{x}
\,.
\end{align}

These Newtonian results can be extended to GR: Thorne has shown that in Asymptotically Cartesian Mass-Centered coordinates the metric can be written in a form like
%
\begin{align}
g_{00} =-1 + \frac{2M}{r} + \sum _{\ell\geq2} \frac{1}{r^{\ell+1}}
\qty(
    2 \frac{(2 \ell-1)!!}{\ell!} M^{<i_1 \dots i_\ell} n^{<i_1} \dots n^{i_\ell} + \dots
)
\,.
\end{align}

We can define the mass multipole moments and the current multipole moments.

\end{document}