\label{sec:theory}
\subsection{Mathematical Framework}
\label{sec:mathFramework}
Let be $\bar{\theta}(t)$ a vector describing the plant status in the phase space; the dynamic of the plant, including the control system, can be summarized by the following equation~\cite{MathFrameworkMC2013}:
\begin{equation}
\frac{\partial \bar{\theta}}{\partial t} = \bar{H}(\theta(t),t)
\label{eq:SystemDynamics}
\end{equation}
In the above equation it is assumed the time differentiability in the phase space. Performing an arbitrary decomposition of the phase space, the following statement is obtained:
\begin{equation}
\bar{\theta}=\binom{\bar{x}}{\bar{v}}
\label{eq:firstDecomposition}
\end{equation}
The decomposition is made in such a way that $\bar{x}$ represents the unknowns solved by RELAP-7, while $\bar{v}$ are the variables directly controlled by the control system (i.e., RAVEN). Equation~\ref{eq:SystemDynamics} can now be rewritten as follows:
\begin{equation}
\begin{cases}
\dfrac{\partial \bar{x}}{\partial t} = \bar{F}(\bar{x},\bar{v},t) \\
\dfrac{\partial \bar{v}}{\partial t} = \bar{V}(\bar{x},\bar{v},t) \\
\end{cases}
\label{eq:generalSystemEquation}
\end{equation}
Note that the function $\bar{V}(\bar{x},\bar{v},t)$ representing the control system, does not depend on the knowledge of the complete status of the system but on a restricted subset (i.e. control variables) $\bar{C}$:
%Why is V still a function of x and v?
\begin{equation}
\begin{cases}
\dfrac{\partial \bar{x}}{\partial t} = \bar{F}(\bar{x},\bar{v},t) \\
\bar{C} = \bar{G}(\bar{x},t) \\
\dfrac{\partial \bar{v}}{\partial t} = \bar{V}(\bar{x},\bar{v},t)
\end{cases}
\label{eq:generalSystemEquationwithControl}
\end{equation}
The system of equations in Eq.~\ref{eq:generalSystemEquationwithControl} is fully coupled and has commonly been solved by an operator splitting approach. The reasons for this choice are several:
\begin{itemize}
\item Control system reacts with an intrinsic delay
\item The reaction of the control system might move the system between two different discrete states and
therefore numerical errors will be always of first order unless the discontinuity is treated explicitly.
\end{itemize}
RAVEN uses this approach to solve Eq.~\ref{eq:generalSystemEquationwithControl} which now becomes:
\begin{equation}
\begin{cases}
\dfrac{\partial \bar{x}}{\partial t} = \bar{F}(\bar{x},\bar{v}_{t_{i-1}},t) \\
\bar{C} = \bar{G}(\bar{x},t) & t_{i-1}\leq t\leq t_{i} = t_{i-1} + \Delta t_{i}\\
\dfrac{\partial \bar{v}}{\partial t} = \bar{V}(\bar{x},\bar{v}_{t_{i-1}},t) \\
\end{cases}
\label{eq:generalSystemEquationwithControlSplitting}
\end{equation}
Even if all information needed is contained in $\bar{x}$ and $\bar{v}$, it is not often practical and efficient to implement the control logic for complex system . Consequently, a system of auxiliary variables has been introduced.

The auxiliary variables are those that in statistical analysis are artificially added, when possible, to non-Markovian systems into the space phase to obtain a Markovian behavior back, so that only the information of the previous time step is needed to determine the future status of the system.
Thus, the introduction of the auxiliary variables into the mathematical framework leads to the following formulation of Eq.~\ref{eq:generalSystemEquationwithControlSplitting}:
\vspace{-2mm}
\begin{equation}
\begin{cases}
\dfrac{\partial \bar{x}}{\partial t} = \bar{F}(\bar{x},\bar{v}_{t_{i-1}},t) \\
\bar{C} = \bar{G}(\bar{x},t) & t_{i-1}\leq t\leq t_{i} = t_{i-1} + \Delta t_{i}\\
\dfrac{\partial \bar{a}}{\partial t} = \bar{A}(\bar{x},\bar{C},\bar{a}_{t_{i-1}},\bar{v}_{t_{i-1}},t) \\
\dfrac{\partial \bar{v}}{\partial t} = \bar{V}(\bar{x},\bar{C},\bar{v}_{t_{i-1}},\bar{a},t)
\end{cases}
\label{eq:generalSystemEquationwithControlSplittingAndAux}
\end{equation}

\subsection{Software Overview}
RAVEN~\cite{alfonsiMC}, is plugged into the software environment MOOSE~\cite{MOOSE}. MOOSE is a computer simulation framework,  developed at Idaho National Laboratory (INL),which simplifies the process for predicting the behavior of complex systems and developing non-linear, multi-physics simulation tools. MOOSE provides the algorithms for the solution of generic partial differential equations, and all the manipulation tools needed to extract information from the solution field.  This framework has been used to construct and develop the Thermal-Hydraulic code RELAP-7, giving an enormous flexibility in the coupling procedure with RAVEN.

RELAP-7 is the next generation nuclear reactor system safety analysis. It will become the main reactor systems simulation toolkit for the RISMC (\textbf{R}isk \textbf{I}nformed \textbf{S}afety \textbf{M}argin \textbf{C}haracterization)~\cite{mandelliANS_RISMC} project and the next generation tool in the RELAP reactor safety/systems analysis application series.

RAVEN has been developed in a highly modular and pluggable way in order to enable easy integration of different programming languages (i.e., \verb!C++!, \verb!Python!) and coupling with other MOOSE based applications and not only. The code consists of four main modules:
\vspace{-5mm}
\begin{itemize}
\itemsep0em
\item RAVEN/RELAP-7 interface
\item Python Control Logic
\item External Python Manager
\item Graphical User Interface
\end{itemize}
\vspace{-5mm}
The RAVEN/RELAP-7 interface, coded in \verb!C++!, is the container of all the tools needed to interact with RELAP-7/MOOSE. It has been designed in order to be general and pluggable with different solvers simultaneously in order to allow an easier and faster development of the control logic/PRA capabilities for multi physics applications.
The interface provides all the capabilities to extract the monitored quantities and accordingly modify the controlled parameters in the RELAP-7/MOOSE calculation.

The control logic module is used to drive a RAVEN/RELAP-7 simulation, as the real plant control system would do. It is implemented by the user via \verb!Python! scripting. The reason of this choice is to try to preserve generality of the approach in the initial phases of the project so that further specialization (pre-generated control logic blocks)  is possible and  inexpensive. The implementation of the control logic via \verb!Python! is rather convenient and flexible. The user only needs to know few \verb!Python! syntax rules in order to build an input. Though simple by itself, the GUI will provide tools to automate the construction of the control logic scripting in order to minimize user effort.

The core of PRA analysis is contained in an external driver/manager. It consists of a \verb!Python! framework that contains the capabilities and interfaces to drive a PRA analysis. Its basic infrastructure in connection with the DET module will be discussed in section~\ref{sec:CPUInfrastructure}

As previously mentioned, a GUI is not required to run RAVEN, but it represents an added value to the whole code. The GUI is compatible with all the capabilities actually available in RAVEN.  Its development is performed using \verb!PyQt4!, which is a \verb!Python! interface for \verb!Qt! (https://qt-project.org). \verb!Qt!  is a popular library used for cross-platform GUI development. RAVEN’s GUI is developed starting from Peacock, which is a GUI interface for generic MOOSE based applications. Because RELAP-7 is rather different from the other MOOSE based applications, much effort has been required to specialize Peacock for RAVEN and further addition will continue to follow RELAP-7 development.
\vspace{-5mm}


\appendix
\chapter{Drift-Kinetic Basis Transformation}
\label{app:tlkpj}

In the present Appendix, we derive the expressions for the coefficients $T_{alk}^{pj}$ appearing in \cref{eq:tlkpj}. These coefficients allows us to express up to order $\epsilon \epsilon_\nu$ the relation between fluid $\bm M_{a}^{lk}$ and guiding-center $N_{a}^{lk}$ moments via \cref{eq:CoulDKmom}.
As a first step, we define a transformation similar to \cref{eq:tlkpj} but with isotropic temperatures between both {bases}

\be
    \begin{split}
        c_a^l P_l(\xi_a)L_k^{l+1/2}(c_a^2)=&\sum_{p=0}^{l+2k}\sum_{j=0}^{k+\floor{l/2}}\overline T_{lka}^{pj} H_p\left(\frac{v_\parallel-u_{\parallel a}}{v_{th a}}\right) L_j\left(\frac{v^{'2}_{\perp}}{v_{th a}^2}\right),
    \end{split}
    \label{eq:deftbarlkpj}
\ee

\noindent with the inverse transformation

\be
    \begin{split}
        H_p\left(\frac{v_\parallel-u_{\parallel a}}{v_{th a}}\right)L_j\left(\frac{v^{'2}_{\perp}}{v_{th a}^2}\right) =& \sum_{l=0}^{p+2j}\sum_{k=0}^{j+\floor{p/2}}\left(\overline T^{-1}\right)_{pj a}^{lk} \\
        &\times c_a^l P_l(\xi_a)L_k^{l+1/2}(c_a^2),
    \end{split}
\ee

The relation between the coefficients $\left(\overline T^{-1}\right)_{pj}^{lk}$ and $\overline T_{lk}^{pj}$ is given by

\be
    \left(\overline T^{-1}\right)_{pj}^{lk}=\frac{\sqrt{\pi}2^p p!(l+1/2)k!}{(k+l+1/2)!}\overline T_{lk}^{pj}.
\ee

By integrating both sides of \cref{eq:deftbarlkpj} over the whole velocity space, we can write $\overline{T}_{lk}^{pj}$ as
%
\begin{align}
    T_{lk}^{pj}=\int P_l(\xi)c^l L_k^{l+1/2}(c^2)\frac{H_p(s_\parallel) L_j(s_\perp^2)}{2^p p! \sqrt{\pi}}e^{-s_\parallel^2-s_\perp^2}ds_\parallel ds_\perp^2,
\label{eq:deftlkpj1}
\end{align}
%
where we suppressed the species index $a$ for simplicity, and find
%
\begin{equation}
    \begin{split}
        \overline T_{lk}^{pj}&=\sum_{q=0}^{\floor{l/2}}\sum_{v=0}^{\floor{p/2}}\sum_{i=0}^{k}\sum_{r=0}^{q}\sum_{s=0}^{\text{min}(j,i)}\sum_{m=0}^{k-i}\frac{(-1)^{q+i+j+v+m}}{2^{\frac{3l+p}{2}+m+v-r}}\\
        &\times\binom{l}{q}\binom{2(l-q)}{l}\binom{q}{r}\binom{r}{j-s}\binom{r}{i-s}\binom{s+r}{s}{r!}{}\\
        &\times\frac{(k-i+l-1/2)!(l+p+2(m-r-v)-1)!!}{(p-2v)!(k-i-m)!(l+m-1/2)!v!m!}.
    \end{split}
\end{equation}

We then integrate both sides of \cref{eq:tlkpj} with weights $H_l(s_{\parallel a})L_j(s_{\perp a}^2)$, with the argument transformation

\begin{equation}
\begin{split}
        H_p(s_{\parallel a})=\left(\frac{T_a}{T_{\parallel a}}\right)^{p/2}\sum_{k=0}^{\floor{p/2}}&\frac{p!}{k!(p-2k)!}\left(1-\frac{T_{\parallel a}}{T_a}\right)^kH_{p-2k}\left(\frac{v_\parallel-u_{\parallel a}}{v_{th a}}\right),
\end{split}
\end{equation}

\noindent and

\begin{equation}
\begin{split}
    L_j(s_{\perp a}^2)=\sum_{k=0}^{j}&\binom{j}{j-k}\left(\frac{T_a}{T_{\perp a}}\right)^k \left(1-\frac{T_a}{T_{\perp a}}\right)^{j-k}L_{k}\left(\frac{v_{\perp}^{'2}}{v_{th a}^2}\right),
\end{split}
\end{equation}

\noindent to find the relation between the isotropic and anisotropic temperature coefficients

\be
    \begin{split}
        T_{alk}^{pj}=&\sum_{m=0}^{l+2k}\sum_{n=0}^{k+\floor{l}{2}}\sum_{z=0}^{n}\sum_{d=0}^{\floor{m/2}}\binom{n}{n-z}\frac{m!\delta_{z,j}\delta_{p,m-2d}}{d!(m-2d)!}\\
        &\times\left(\frac{T_{\parallel a}}{T_a}\right)^{p/2}\left(\frac{T_{\perp a}}{T_a}\right)^{z}\left(1-\frac{T_a}{T_{\parallel a}}\right)^{d}\left(1-\frac{T_{\perp a}}{T_a}\right)^{n-z}{\overline{T}_{lk}^{m n}},
    \end{split}
    \label{eq:tlkpjexact}
\ee

\be
    \begin{split}
        \left(T^{-1}_a\right)_{pj }^{lk}=&\sum_{z=0}^{j}\sum_{d=0}^{\floor{p/2}}\sum_{t=0}^{p-2d+2z}\sum_{v=0}^{z-d+\floor{p}{2}}\binom{j}{j-z}\frac{p!\delta_{l,t}\delta_{k,v}}{d!(p-2d)!}\\
        &\times\left(\frac{T_{ a}}{T_{\parallel a}}\right)^{p/2}\left(\frac{T_{a}}{T_{\perp a}}\right)^{z}\left(1-\frac{T_{\parallel a}}{T_{ a}}\right)^{d}\left(1-\frac{T_{ a}}{T_{\perp a}}\right)^{j-z}\left(\overline{T^{-1}}\right)_{p-2d z}^{t v}.
    \end{split}
    \label{eq:tlkpjminus1exact}
\ee

A more efficient algorithm can be found as follows.
%
First, we expand the product $P_l(\xi)c^l L_k^{l+1/2}(c^2)$ into products of $s_\parallel$ and $s_\perp^2$ in order to write \cref{eq:deftlkpj1} in terms of $s_\parallel$ and $s_\perp^2$ only
%
\begin{align}
    P_l(\xi)c^l L_k^{l+1/2}(c^2)&=\sum_{i=0}^{\floor{l/2}}\sum_{m=0}^k\sum_{r=0}^{m+i}\binom{2l-2i}{l}\binom{l}{i}\binom{m+i}{r}\frac{(-1)^{i+m}(l+k+1/2)!)}{2^l(k-m)!(l+m+1/2)!m!}\nonumber\\
    &\times\frac{s_\parallel^{l-2i+2r}s_\perp^{2(m+i-r)}}{(T_\parallel/T)^{l/2-i+r}(T_\perp/T)}.
\end{align}
%
We then perform the parallel and perpendicular integrations separately, using the fact that
%
\begin{equation}
    \int_{-\infty}^{\infty} x^n \frac{H_p(x)}{2^p p! \sqrt{\pi}}e^{-x^2}dx=\frac{n!}{2^n}\frac{1-\mod(n-p,2)}{\left(\frac{n-p}{2}\right)!p!},
\label{eq:inthp1}
\end{equation}
%
and
%
\begin{equation}
        \int_0^{\infty} x^m L_j(x) e^{-x}dx = m!\binom{m}{m-j}(-1)^j.
\label{eq:intlj1}
\end{equation}
%
Finally, we apply \cref{eq:inthp1,eq:intlj1} to \cref{eq:deftlkpj1}, yielding
%
\begin{align}
    T_{lk}^{pj}&=\sum_{i=0}^{\floor{l/2}}\sum_{m=0}^k\sum_{r=0}^{m+i}\binom{2l-2i}{l}\binom{l}{i}\binom{m+i}{r}\frac{(-1)^{i+m+j}(l+k+1/2)!}{2^l(k-m)!(l+m+1/2)!m!}\nonumber\\
    &\times\binom{m+i-r}{m+i-r-j}\frac{(l-2i+2r)!}{2^{l-2i+2r}}\frac{1-\mod(l-p,2)}{\left(\frac{l-p}{2}-i+r\right)!p!}(m+i-r)!.
\end{align}

\chapter{Expressions for the Moments of the Collision Operator}
\label{app:cabmoments}

In the present Appendix, we present the expressions for the guiding-center moments of the collision operator relevant for the fluid model in \cref{sec:fluidmodel}.
The collision operator moments satisfy particle conservation
\be
    C_{ab}^{00}=0,
\ee

\noindent and momentum conservation {at lowest order}

\be
    C_{aa}^{10}=0,
\ee

\begin{equation}
    C_{ei}^{10}=-\frac{m_i}{m_e}\frac{v_{th\parallel i}}{v_{th \parallel e}}C_{ie}^{10}{+O({m_e/m_i})}.
\end{equation}

\noindent Both the like-species and electron-ion satisfy energy conservation exactly, {while the ion-electron operator satisfies \cref{eq:cabenergy} at zeroth order in $\delta_a$}

\begin{equation}
    T_{\parallel a}C_{ab}^{20}-\sqrt{2}T_{\perp a} C_{ab}^{01} = 0.
    \label{eq:cabenergy}
\end{equation}

{The remaining moments $C_{ab}^{pj}$, in the linear transport regime with $\Delta T_a/T_a = (T_{\parallel a} - T_{\perp a})T_a \sim N^{11}\sim N^{30} \sim (u_{\parallel e}-u_{\parallel i})/v_{the} \sim \delta_a$, for ion-electron collisions are given by}

\begin{align}
    C_{ie}^{10}&=-\frac{m_e}{m_i}\frac{v_{th \parallel i}}{v_{th \parallel e}}C_{ei}^{10},\\
    C_{ie}^{20}&=\sqrt{2}\nu_{ei}\frac{m_e}{m_i}\left(\frac{T_e-T_i}{T_i}\right)-\frac{2 \sqrt{2} \nu_{ei}}{3}\frac{m_e}{m_i}\frac{T_e}{T_i}\frac{\Delta T_i}{T_i},\\
    C_{ie}^{01}&=-2\nu_{ei}\frac{m_e}{m_i}\left(\frac{T_e-T_i}{T_i}\right)-\frac{2 \nu_{ei}}{3}\frac{m_e}{m_i}\frac{T_e}{T_i}\frac{\Delta T_i}{T_i},\\
    C_{ie}^{30}&=-\nu_{ei}\sqrt{\frac{3}{2}}\frac{m_e}{m_i}\frac{Q_{\parallel i}}{n T_i v_{thi}},\\
    C_{ie}^{11}&=3 \nu_{ei}\frac{m_e}{m_i}\frac{Q_{\perp i}}{n T_i v_{thi}},
\end{align}

\noindent {for electron-ion collisions}

{
\begin{align}
    C_{ei}^{10} &= -\frac{\sqrt{2}\nu_{ei}}{6 \pi^{3/2}}\frac{u_{\parallel e}-u_{\parallel i}}{v_{the}}+\frac{\sqrt{2}\nu_{ei}}{10 \pi^{3/2}}\frac{Q_{\parallel e}+2 Q_{\perp e}}{n T_e v_{the}},\\
    C_{ei}^{20}&=-\frac{2 \sqrt{2}\nu_{ei}}{15 \pi^{3/2}}\frac{\Delta T_e}{T_e},\\
    C_{ei}^{30}&= \frac{\sqrt{3}\nu_{ei}}{10 \pi^{3/2}}\frac{u_{\parallel e}-u_{\parallel i}}{v_{the}}-\frac{ \nu_{ei}}{70 \sqrt{3} \pi^{3/2}}\frac{31 Q_{\parallel e} - 2 Q_{\perp e}}{n T_e v_{the}},\\
    C_{ei}^{11}&= \frac{ \nu_{ei}}{5 \sqrt{2} \pi^{3/2}}\frac{u_{\parallel e}-u_{\parallel i}}{v_{the}}+\frac{ \nu_{ei}}{150 \sqrt{2} \pi^{3/2}}\frac{Q_{\parallel e}-94 Q_{\perp e}}{n T_e v_{the}},\\
\end{align}
}
\noindent {and for like-species collisions}
{
\begin{align}
    C_{aa}^{20}&=0,\\
    C_{aa}^{30}&=-\frac{2 \sqrt{2}}{125 \sqrt{3} \pi^{3/2}}\frac{\nu_{aa}}{n T_a v_{tha}}\left(19 Q_{\parallel a}-7 Q_{\perp a}\right),\\
    C_{aa}^{11}&=-\frac{2}{375 \pi^{3/2}}\frac{\nu_{aa}}{n T_a v_{tha}}\left(7 Q_{\parallel a}-121 Q_{\perp a}\right).
\end{align}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Spherical Basis Tensors}
\label{app:basistensors}

We start with the definition of the $\mathbf{Y}^l(\mathbf v)$ tensor in terms of spherical basis tensors $\mathbf e^{lm}$ in \cref{eq:ylvfull}.
%
For the $l=1$ case, \cref{eq:ylvfull} yields
%
\begin{equation}
    \mathbf Y^1(\mathbf v) = \mathbf v = \sqrt{\frac{4 \pi}{3}}v \sum_{m=-1}^1 Y_{1m}(\phi,\theta) \mathbf e^{1m}.
\label{eq:Y1defe}
\end{equation}
%
The spherical basis vectors $\mathbf e^{1m}$ can then be derived from \cref{eq:Y1defe} by decomposing the vector $\mathbf v$ in spherical coordinates as
%
\begin{equation}
    \mathbf v = v\left(\sin \phi \cos \theta \mathbf e_x+\sin \phi \sin \theta \mathbf e_y+\cos \phi \mathbf e_z\right),
\end{equation}
%
and using the identities for the spherical harmonics
%
\begin{equation}
    Y_{1m}(\phi,\theta)=
\begin{cases}
    \sqrt{\frac{3}{8 \pi}}\sin \phi e^{-i \theta}, &m=-1,\\
    \sqrt{\frac{3}{4 \pi}}\cos \phi, &m=0,\\
    -\sqrt{\frac{3}{8 \pi}}\sin \phi e^{i \theta}, &m=1,\\
\end{cases}
\end{equation}
%
therefore obtaining
%
\begin{equation}
    \mathbf e^{1m}=
\begin{cases}
    \frac{\mathbf e_x-i \mathbf e_y}{\sqrt{2}}, &m=-1,\\
    \mathbf e_z, &m=0,\\
    -\frac{\mathbf e_x+i \mathbf e_y}{\sqrt{2}}, &m=1.\\
\end{cases}
\end{equation}

We now construct spherical basis tensors $\mathbf e^{lm}$ from the spherical basis vectors $\mathbf e^{1m}$ leveraging the techniques developed for the angular momentum formalism in quantum mechanics \citep{Zettili2009,Snider2018}.
%
Indeed, the basis vectors $\mathbf e^{1m}$ are eigenvectors of the angular momentum matrix $G_z$
%
\begin{equation}
    G_z=i
  \begin{pmatrix}
    0 & -1 & 0\\
    1 &  0 & 0\\
    0 &  0 & 0
  \end{pmatrix},
\end{equation}
%
with eigenvalue $m$, that is
%
\begin{equation}
    G_z \cdot \mathbf e^{1m} = m \mathbf e^{1m}.
\end{equation}
%
In general, the angular momentum matrices along any axis $n={x,y,z}$ are given by
%
\begin{equation}
    G_{n} = -i \mathbf e_{n} \cdot \epsilon,
\label{eq:gnmatr}
\end{equation}
%
with $\epsilon$ the standard Levi-Civita tensor.
%
In index notation, \cref{eq:gnmatr} can be written as
%
\begin{equation}
    \left({G_{n}}\right)_{kl}=-i\sum_{j=1}^3\left(e_{n}\right)_j \epsilon_{jkl}.
\end{equation}
%
The raising $G_+$ and lowering $G_-$ operators (corresponding to the ladder operators in quantum mechanics) are defined by
%
\begin{equation}
    G_{\pm}=G_x \pm i G_y.
\end{equation}
%
The allow us to obtain the basis vectors $\mathbf e^{1\pm1}$ from $\mathbf e^{10}$ using
%
\begin{equation}
    G_{\pm}\mathbf e^{0m}=\mathbf e^{1\pm}.
\end{equation}
%
Finally, we note that  the dual basis $\mathbf e^{1}_m = (\mathbf e^{1}_m)^* = (-1)^m \mathbf e^{1-m}$, together with $\mathbf e^{1m}$, satisfy
%
\begin{equation}
    \mathbf e^{1m} \cdot \mathbf e^{1}_{m'} = \delta_{m,m'}.
\label{eq:orthoe}
\end{equation}

To obtain the spherical tensor basis $\mathbf e^{l m}$ for the irreducible tensors $\mathbf Y^{l}$, we start with the spherical basis tensor
%
\begin{equation}
    \mathbf e^{ll}=\mathbf e^{11}\mathbf e^{11}...\mathbf e^{11},
\end{equation}
%
formed by the product of $l$ basis vectors $\mathbf e^{11}$.
%
Indeed, similarly to $\mathbf Y^l(\mathbf v)$, this tensor is of rank $l$, symmetric, and traceless between any of its indices, as $\mathbf e^{11}\cdot \mathbf e^{11} = 0$.
%
Furthermore, we note that $\mathbf e^{ll}$ is an eigenvector with eigenvalue $l$ of the angular momentum tensor $G_z^{l}$, with $G_n^{l}$ defined by
%
\begin{equation}
    \left[G_n^{l} \cdot T^l\right]_{j k ... l}=\sum_{j'k'...l'}\left\{\left[G_n\right]_{jj'}\delta_{kk'}...\delta_{ll'}+\left[ \delta_{jj'}G_n\right]_{kk'}...\delta_{ll'}+...+\delta_{jj'}\delta_{kk'}...\left[G_n\right]_{ll'}\right\} T^l_{j'k'...l'},
\end{equation}
%
where $T^l$ is an arbitrary tensor of rank $l$.
%
The remaining basis tensor elements $\mathbf e^{l m}$ can be obtained by applying the tensorial lowering operator $G^l_-=G_x^{l}-i G_y^{l}$ to $\mathbf e^{ll}$, namely
%
\begin{equation}
    \mathbf e^{l m} = \sqrt{\frac{(l+m)!}{(2l)!(l-m)!}}G^{l}_-\cdot^{l-m}\mathbf e^{ll},
\label{eq:elmbasistensor}
\end{equation}
%
with $m=-l,-l+1,...,-1,0,1,...,l$.
%
The normalization factor in \cref{eq:elmbasistensor} is obtained by requiring that the contravariant $\mathbf e^{lm}$ and the covariant $\mathbf e^l_m=(\mathbf e^l_m)^*$ basis tensors form an orthonormal basis, i.e.,
%
\begin{equation}
    \mathbf e^{l m} \cdot \mathbf e^{l}_{m'} = \delta_{m,m'}.
\end{equation}
%
For computational purposes, we note that the tensor $\mathbf e^{l m}$ can also be written as a function of the basis vectors $\mathbf e^{1m}$ as \citep{Snider2018}
%
\begin{equation}
    \mathbf e^{l m}=N_{lm}\sum_{n=0}^{\floor{\frac{l+m}{2}}}a_n^{lm}\left\{(\mathbf e^{11})^{m+n}(\mathbf e^{1-1})^{n}(\mathbf e^{10})^{l-m-2n}\right\}_{TS},
\end{equation}
%
where $N_{lm}=\sqrt{(l+m)!(l-m)!2^{l-m}/(2l)!}$ and $a_n^{lm}=l!/[2^n n!(m+n)!(l-m-2n)!]$.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Gyrokinetic Basis Transformation}
\label{app:tlkpj1}

In this section, we derive a closed form expression for the $T_{lkm}^{pj}$ and $(T^{-1})^{lkm}_{pj}$ coefficients defined in \cref{eq:plljhplj,eq:plljhpljminus1}.
%
By multiplying \cref{eq:plljhplj} by a Hermite and a Laguerre polynomial and by an exponential of the form $e^{-\overline v^2}$, and integrating over the whole $\overline v_\parallel$ and $\overline \mu$ space, we obtain the following integral expression for $T_{lkm}^{pj}$
%
\begin{equation}
    T_{lkm}^{pj}=\frac{v_{tha}^{m-l}}{2^p p! \sqrt{\pi}} \int \frac{\overline v^l}{\overline v_\perp^m} P_l^m\left(\frac{\overline v_\parallel}{\overline v}\right) L_k^{l+1/2}\left(\frac{\overline v_{tha}^m}{\overline v_\perp^m}\right) H_p\left(\frac{\overline v_{\parallel a}}{v_{tha}}\right)L_j\left(\frac{\overline v_\perp^2}{v_{tha}^2}\right) e^{-\frac{v^2}{v_{tha}^2}}\frac{d \bm v}{2 \pi}.
\label{eq:appbas1}
\end{equation}
%
We first write the integrand in \cref{eq:appbas1} in terms of $\overline \xi=\overline v_\parallel/\overline v$ and $\overline v$ coordinates using the basis transformation in \cref{eq:plljhpljminus1}, yielding
%
\begin{equation}
\begin{split}
     T_{lkm}^{pj}&= \sum_{l'=0}^{p+2j}\sum_{k'=0}^{j+\floor{p/2}}\frac{(l+1/2)k!}{(l+k+1/2)!}T_{l'k'}^{pj}\\
     &\times\int_{-1}^1 \frac{P_l^m(\overline \xi) P_{l'}(\overline \xi)}{(1-\overline \xi)^2} d \overline \xi \int_0^\infty x_a^{(l+l'-m+1)/2}L_k^{l+1/2}(x_a)L_{k'}^{l'+1/2}(x_a) dx_a,
\end{split}
\label{eq:appbas2}
\end{equation}
%
where we used the fact that $(T^{-1})_{lk}^{pj}=T_{lk}^{pj}\sqrt{\pi}2^p p! k! (l+1/2)/(k+l+1/2)!$ \citep{Jorge2017}.
%
The first integral in \cref{eq:appbas2} is performed by expanding $P_{l}$ as a finite sum of the form
%
\begin{equation}
    P_{l}(x)=\sum_{s=0}^l c_s^l x^s,
\end{equation}
%
with the coefficients $c_s^l=2^l[(l+s-1)/2]!/[s!(l-s)!((s-l-1)/2)!]$, and using the relation between associated Legendre functions $P_l^m(x)$ and Legendre polynomials $P_l(x)$
%
\begin{equation}
    P_l^m(x) = (-1)^m(1-x^2)^{m/2}\frac{d^m P_l(x)}{dx^m}.
\end{equation}
%
The second integral in \cref{eq:appbas2} is performed by using the expansion of the associated Laguerre polynomials in \cref{eq:asslaguerre}.
%
The $T_{lkm}^{pj}$ coefficient can then be written as
%
\begin{align}
    T_{lkm}^{pj}&=\sum_{l'=0}^{p+2j}\sum_{k'=0}^{j+\floor{p/2}} T_{l'k'}^{pj}\frac{(l'+1/2)k'!}{(l'+k'+1/2)!} \sum_{m_1=0}^k\sum_{m_2=0}^{k'}\sum_{s_1=m}^l\sum_{s_2=0}^{l'}L_{k m_1}^l L_{k' m_2}^{l'}\nonumber\\
    &\times \frac{c_{s_1}^l c_{s_2}^{l'}}{2} \frac{s_1!}{(s_1-m)!} \frac{\left[1+(-1)^{s_1+s_2-m}\right]}{s_1+s_2+1-m}\left(m_1+m_2+\frac{l+l'-m+1}{2}\right)!.
\end{align}
%
The inverse transformation coefficients $(T^{-1})^{lkm}_{pj}$ defined by \cref{eq:plljhpljminus1} can be found similarly, yielding
%
\begin{equation}
    (T^{-1})^{lkm}_{pj}=\frac{2^p p! \sqrt{\pi} k! (l+1/2)(l-m)!}{(k+l+1/2)!(l+m)!}T_{lkm}^{pj}.
\end{equation}


\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath,amssymb,amsthm}
\usepackage{hyperref}

\newtheorem{theorem}{Theorem}[section]
\theoremstyle{definition}
\newtheorem{definition}{Definition}[theorem]
\newtheorem{corollary}{Corollary}[theorem]
\newtheorem{lemma}[theorem]{Lemma}
\newcommand\numberthis{\stepcounter{equation}{1}\tag{\theequation}}

\title{Mathematics Handout - Logaritmics}
\author{Daniel Frederico Lins Leite}
\date{July 2016}

\begin{document}
\section{Introduction}
\begin{definition}[Log Definition]\label{definitions:log}
	\begin{align*}
		log_a b=c \\
		a^{log_a b}=a^c \\
		b=a^c \\
		log_a b=log_a a^c \\
		log_a b= c
	\end{align*}
\end{definition}
\begin{theorem}[Logarithm Product Rule]\label{log:product.rule}
	\begin{align*}
	log_x{(A*B)}=log_x A + log_x B
	\end{align*}
	\begin{proof}
		\begin{align}
			x^l = A \\
			log_x {x^l} = log_x A \\
			l = log_x A \label{logproductrulel} \\
			\nonumber\\
			x^m = B \\
			log_x {x^m} = log_x B \\
			\label{logproductrulem} m = log_x B \\
			\nonumber\\
			x^n = A*B \\
			log_x{x^n} = log_x{(A*B)} \\
			\label{logproductrulen}n = log_x{(A*B)} \\
			\nonumber\\
			log_x{(A*B)} = n \\
			x^n = A*B \\
			x^n	= x^l*x^m \\
			x^n	= x^{l+m} \\
			n = l + m && \text{use (\ref{logproductrulel}) (\ref{logproductrulem}) 	(\ref{logproductrulen})}\\
			log_x{(A*B)} = log_x A + log_x B
		\end{align}
	\end{proof}
\end{theorem}
\begin{theorem}[Logarithm Power Rule]\label{log:power.rule}
	\begin{align*}
	log_x{A^B}=B*log_x(A)
	\end{align*}
	\begin{proof}
		\begin{align}
		log_x{(A^B)} \\
		log_x{(\prod_{n=1}^{B}A)}\\
		\sum_{n=1}^{B}(log_x{A}) && \text{use (\ref{log:product.rule})}\\
		log_x{A}*\sum_{n=1}^{B}1\\
		B*log_x{A}
		\end{align}
	\end{proof}
\end{theorem}
\end{document}


\chapter{ALGORITHMS}
% \addcontentsline{toc}{chapter}{Algorithms}

\section{Sample Algorithm}
In Algorithm~\ref{alg1} we show how to calculate $y=x^n$.

\begin{algorithm}
  \caption{Calculate $y = x^n$}
  \label{alg1}
  \begin{algorithmic}
%     \input{algorithms/yxn.alg}
    \REQUIRE $n \geq 0 \vee x \neq 0$
    \ENSURE $y = x^n$

    \STATE $y \leftarrow 1$
    \IF{$n < 0$}
      \STATE $X \leftarrow 1 / x$
      \STATE $N \leftarrow -n$
    \ELSE
      \STATE $X \leftarrow x$
      \STATE $N \leftarrow n$
    \ENDIF

    \WHILE{$N \neq 0$}
      \IF{$N$ is even}
	\STATE $X \leftarrow X \times X$
	\STATE $N \leftarrow N / 2$
      \ELSE[$N$ is odd]
	\STATE $y \leftarrow y \times X$
	\STATE $N \leftarrow N - 1$
      \ENDIF
    \ENDWHILE

%     \endinput
  \end{algorithmic}
\end{algorithm}

\endinput


\section{Real World Signals: Respiratory Sinus Arrhythmia from RR-Intervals}

\begin{enumerate}[label=\alph*), leftmargin=*]
%% a)
\item
%

The standard and averaged periodograms with different window lengths $L \in \{ 50, 100, 200 \}$ are obtained and illustrated in figure \ref{fig:2_4_a}.
In detail, Bartlett's method periodogram is used, where:

\begin{enumerate}[label=\arabic*)]
    \item the signal is split to $M$ non-overlapping segments of length $L$
    \item the standard periodogram (rectangular window) of each segment is calculated
    \item the $M$ periodograms are averaged
\end{enumerate}

Increasing $M$ (or decreasing $L$) trades frequency resolution for variance, which is reflected in \ref{fig:2_4_a},
where the standard periodogram, which can be treated as a special case of the Bartlett's method with $M = 1$, has finest frequency resolution but largest variance,
while for $L = 50$ and $M \rightarrow \mathtt{max}$, variance is minimised in price of larger frequency resolution.

\begin{figure}[h]
    \centering
    \begin{subfigure}{0.49\textwidth}
        \centering
        \includegraphics[height=1.5in]{report/parametric-and-line-spectra/real-world-signals_respiratory-sinus-arrhythmia-from-RR-Intervals/assets/a/standard-trial1}
    \end{subfigure}
    ~
    \begin{subfigure}{0.49\textwidth}
        \centering
        \includegraphics[height=1.5in]{report/parametric-and-line-spectra/real-world-signals_respiratory-sinus-arrhythmia-from-RR-Intervals/assets/a/averaged-trial1}
    \end{subfigure}
    ~
    ~
    \begin{subfigure}{0.49\textwidth}
        \centering
        \includegraphics[height=1.5in]{report/parametric-and-line-spectra/real-world-signals_respiratory-sinus-arrhythmia-from-RR-Intervals/assets/a/standard-trial2}
    \end{subfigure}
    ~
    \begin{subfigure}{0.49\textwidth}
        \centering
        \includegraphics[height=1.5in]{report/parametric-and-line-spectra/real-world-signals_respiratory-sinus-arrhythmia-from-RR-Intervals/assets/a/averaged-trial2}
    \end{subfigure}
    ~
    ~
    \begin{subfigure}{0.49\textwidth}
        \centering
        \includegraphics[height=1.5in]{report/parametric-and-line-spectra/real-world-signals_respiratory-sinus-arrhythmia-from-RR-Intervals/assets/a/standard-trial3}
    \end{subfigure}
    ~
    \begin{subfigure}{0.49\textwidth}
        \centering
        \includegraphics[height=1.5in]{report/parametric-and-line-spectra/real-world-signals_respiratory-sinus-arrhythmia-from-RR-Intervals/assets/a/averaged-trial3}
    \end{subfigure}
    \caption{RRI: standard and averaged periodograms with different window lengths $L$.}
    \label{fig:2_4_a}
\end{figure}

%% b)
\item
%

The three trials were carried out under different breathing conditions, which is reflected by the Breaths per Minute (BPM) rate.
Table \ref{tab:2_4_b} summarises the conditions and the corresponding expected and observed BPM measurements for each trial.

\begin{table}[h]
\centering
\begin{tabular}{|c|c|c||c|}
\hline
& \textbf{Conditions} & \textbf{Expected Range} (BPM) & \textbf{Observation} (BPM) \\
\hline
\hline
\textbf{Trial 1} & normal \& unconstraint breathing & $12 - 35$ & $19.69$ \\
\hline
\textbf{Trial 2} & fast breathing & $35 - 50$ & $49.92$ \\
\hline
\textbf{Trial 3} & slow breathing & $8 - 15$ & $15$ \\
\hline
\end{tabular}
\caption{RRI: conditions and observed BPM.}
\label{tab:2_4_b}
\end{table}

The observed peaks for the three trials are at frequencies $f_{1} = 0.1641\ Hz$, $f_{2} = 0.416\ Hz$ and $f_{3} = 0.125\ Hz$.
For trial 1, both the standard and the averaged periodograms have a peak at $f_{1} = 0.1641\ Hz$, however the averaged periodograms due to their inadequate frequency resolution
fail to capture its harmonics, which are hardly visible also at the standard periodogram. Trial 2 peak at $f_{2} = 0.416\ Hz$ and its second and third harmonics are visible
using any of the provided methods. Lastly, trial 3 peak at $f_{3} = 0.125\ Hz$ and its harmonics are clearly captures by both the standard and the averaged periodograms.

\pagebreak

%% c)
\item
%

The power spectral density of the three trials is estimated by fitting $p$ order AR processes and figures \ref{fig:2_4_c_1}, \ref{fig:2_4_c_2} and \ref{fig:2_4_c_3} are obtained.

\begin{figure}[h]
    \centering
    \includegraphics[height=1.5in]{report/parametric-and-line-spectra/real-world-signals_respiratory-sinus-arrhythmia-from-RR-Intervals/assets/c/standard_ar-trial1}
    \caption{RRI Trial 1: AR process spectral estimation.}
    \label{fig:2_4_c_1}
\end{figure}

For trial 1, for $p \geq 11$, the fundamental frequency $f_{1} = 0.1641\ Hz$ and its 3 first harmonics are identified, corraborating with the results of the previous part.

\begin{figure}[h]
    \centering
    \includegraphics[height=1.5in]{report/parametric-and-line-spectra/real-world-signals_respiratory-sinus-arrhythmia-from-RR-Intervals/assets/c/standard_ar-trial2}
    \caption{RRI Trial 2: AR process spectral estimation.}
    \label{fig:2_4_c_2}
\end{figure}

Figure \ref{fig:2_4_c_2} depicts the AR spectral estimate of trial 2, which again for $p \geq 11$ adequately captures the fundamental frequency and its first three harmonics.

\begin{figure}[h]
    \centering
    \includegraphics[height=1.5in]{report/parametric-and-line-spectra/real-world-signals_respiratory-sinus-arrhythmia-from-RR-Intervals/assets/c/standard_ar-trial3}
    \caption{RRI Trial 3: AR process spectral estimation.}
    \label{fig:2_4_c_3}
\end{figure}

Last but not least, for $p \geq 16$ trial 3 AR(p) process model discriminated all six first harmonics, verifying the respiration rate reported in the previous part.

Overall, the AR process models can provide reliable estimates when the generative process order $p$ is known, or noise power is negligible compared to the signal power.
When under-modelling is performed ($p < p_{true}$) the estimates cannot identify the frequency peaks, while in presence of noise, over-modelling ($p > p_{true}$) can
lead to overfitting noise and thus providing faulty peaks. Nonetheless, compared to the standard and averaged periodogram methods, the variance, frequency resolution trade-off
is not present in case of AR models.

%
\end{enumerate}


\chapter{Methods}
\begin{comment}
	0. Verlet Step
	1. Describe the Lenard Jones Potential
	2. Describe the Berendsen Thermostat
	3. Describe the Gupta

\end{comment}
\begin{comment}
	Atoms are discreticed into the Postitions, Velocities and Forces
	Second propagate the atom in the discriticed realm given constant Forces
		-> Velocity-Verlet Integration

	Compute Forces somehow
	-> Potentials
	LJ Potential
	Gupta Potential

	Thermodynamic Effects
	Berendsen Thermostat
		->Gentle Way of resealing the Velocities

\end{comment}
%end general
\begin{comment}
goals of a md simulation
- determine the motion of each atom
	-> solve equation of motion
	-> compute forces
	-> From the dirivation of the potential energy we can get the forces

- disciticed in time

\end{comment}
The goal of a molecular dynamics simulation is to determine the motion of each individual atom. To achieve this we have to solve the equations of motion and compute the forces that affect each atom.
\begin{equation}
	\label{potentialForceEquation}
	\overrightarrow{f_{k}}(\overrightarrow{r_{k}}) = -\cfrac{\displaystyle\partial}{\displaystyle \partial \overrightarrow{r_{k}}} E_{\mathrm{pot}}(\{\overrightarrow{r_{k}}\})
\end{equation}
The forces can be derived from the potential energy as shown in Eq.  \ref{potentialForceEquation} \cite[][]{molDymCourse}.

\section{Integration}
\begin{comment}
- obtain force from the previous equation
- dirivation in v. r.. from the mass
- system can be discribed just by the velocity and postion of each atom
- in the simulation the positions and velocities of the individual atoms have to be tracked and updated accordingly
- most used  is the Velocity-Verlet Algorithm
\end{comment}
From Eq. \ref{potentialForceEquation} we can obtain the force acting on each individual atom with its acceleration, velocity and position as shown in  Eq. \ref{potentialForceEquationForEachAtom}.
\begin{equation}
	\label{potentialForceEquationForEachAtom}
	\overrightarrow{f_{i}} = \cfrac{\displaystyle\partial E_{\mathrm{pot}}}{\displaystyle \partial \overrightarrow{r_{i}}} = m_{i}\overrightarrow{a_{i}} = m_{i}\overrightarrow{\dot{v_{i}}} = m_{i}\overrightarrow{\ddot{r_{i}}}
\end{equation}
As is shown the system can be described just by the velocities and positions of the atoms.
In the implementation we hold these values in a container-class to ensure that they are consecutive in  memory, which speeds up the simulation.
\par
%to porpagate
In the next step we need to propagate the simulation forward in time. A popular algorithms to update the positions and velocities is the Velocity-Verlet integration algorithm.
The scheme is often split up into two steps, the prediction step shown in the Eqs.  \ref{verletPrediction1} and \ref{verletPrediction2}, and the correction step shown in Eq. \ref{verletCorrection} \cite[cf. ][]{molDymCourse}. The force which is needed in the second step can be updated beforehand, based on the new positions from the first step.
%Verlet steps
\begin{equation}
	\label{verletPrediction1}
	\overrightarrow{v_{i}}(t+\Delta t/2) =
	\overrightarrow{v_{i}}(t) +
	\frac{\overrightarrow{f_{i}}(t)\Delta t}{2m_{i}}
\end{equation}

\begin{equation}
	\label{verletPrediction2}
	\overrightarrow{r_{i}}(t+ \Delta t) =
	\overrightarrow{r_{i}}(t) + \overrightarrow{v_{i}}(t + \Delta t/2)\Delta t
\end{equation}

\begin{equation}
	\label{verletCorrection}
	\overrightarrow{v_{i}}(t+\Delta t) = \overrightarrow{v_{i}}(t+\Delta t/2) +
	\frac{\overrightarrow{f_{i}}(t + \Delta t)\Delta t}{2m_{i}}
\end{equation}
We are now able to propagate atoms forward with a constant force, therefore we have to actually model the forces affecting each atom next.

\section{Lenard-Jones-Potential}
\begin{comment}
- pair potential
\end{comment}
%General Formula for the dirivation
A popular pair potential to model interatomic interactions is the Lenard-Jones-Potential.
The goal is to model the Coulomb force and the Pauli repulsion.
\begin{equation}
	V(r) = 4\epsilon\bigg[\Big(\frac{\sigma}{r}\Big)^{12}- \Big(\frac{\sigma}{r}\Big)^{6} \bigg]
\end{equation}
As shown in Eq. \ref{potentialForceEquation} we can derive the forces from the potential energy.
In Eq. \ref {potentialEquationAtoms} we formulate the equation for each atom.
We can acquire the force affecting each atom if we sum up the derivative of the potential energy between atom k and all the other atoms i times the normed vector to atom i from atom k.
\begin{equation}
	\label{potentialEquationAtoms}
	\overrightarrow{f_{k}} = -\frac{\partial E_{\mathrm{pot}}}{\partial  \overrightarrow{r_{k}}} = \sum_{i}^{}\frac{\partial V}{\partial r_{ik}} \hat{r_{ik}}
\end{equation}
%Formulation of the lj potential
To implement the equation we have to derive $\delta V/ \delta r_{ik}$ analytically, which was done using the symbolic python library sympy.
%Potential derivation with python
\begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder]
%\prompt{In}{incolor}{4}{\boxspacing}
\begin{Verbatim}[commandchars=\\\{\}]
\PY{k+kn}{import} \PY{n+nn}{sympy} \PY{k}{as} \PY{n+nn}{sp}
\PY{k+kn}{import} \PY{n+nn}{warnings}
\PY{n}{warnings}\PY{o}{.}\PY{n}{filterwarnings}\PY{p}{(}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{ignore}\PY{l+s+s1}{\PYZsq{}}\PY{p}{)}
\PY{n}{sp}\PY{o}{.}\PY{n}{init\PYZus{}printing}\PY{p}{(}\PY{p}{)}
\PY{n}{eps} \PY{o}{=} \PY{n}{sp}\PY{o}{.}\PY{n}{Symbol}\PY{p}{(}\PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{e}\PY{l+s+s2}{\PYZdq{}}\PY{p}{)}
\PY{n}{sig} \PY{o}{=} \PY{n}{sp}\PY{o}{.}\PY{n}{Symbol}\PY{p}{(}\PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{s}\PY{l+s+s2}{\PYZdq{}}\PY{p}{)}
\PY{n}{rad} \PY{o}{=} \PY{n}{sp}\PY{o}{.}\PY{n}{Symbol}\PY{p}{(}\PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{r}\PY{l+s+s2}{\PYZdq{}}\PY{p}{)}
\PY{n}{energyRad} \PY{o}{=} \PY{l+m+mi}{4} \PY{o}{*} \PY{n}{eps} \PY{o}{*} \PY{p}{(}\PY{p}{(}\PY{n}{sig}\PY{o}{/}\PY{n}{rad}\PY{p}{)}\PY{o}{*}\PY{o}{*}\PY{l+m+mi}{12} \PY{o}{\PYZhy{}} \PY{p}{(}\PY{n}{sig}\PY{o}{/}\PY{n}{rad}\PY{p}{)}\PY{o}{*}\PY{o}{*}\PY{l+m+mi}{6}\PY{p}{)}
\PY{n}{energyRad}\PY{o}{.}\PY{n}{diff}\PY{p}{(}\PY{n}{rad}\PY{p}{)}
	\end{Verbatim}
\end{tcolorbox}

With the codesnippet from above the derivative of the potential was obtained as shown in Eq. \ref{potentialEquationAtomsDirivative}.
\begin{equation}
	\label{potentialEquationAtomsDirivative}
	\frac{\partial V}{\partial r} = 4 \epsilon \left(\frac{6 \sigma^{6}}{r^{7}} - \frac{12 \sigma^{12}}{r^{13}}\right)
\end{equation}
The result from Eq. \ref{potentialEquationAtomsDirivative} can be used to calculate the interatomic forces from Eq. \ref {potentialEquationAtoms}.
We can optimize the implementation by subtracting the force that affects atom k from the forces of atom i, as they have to be the same just with the opposite direction and therefore sign.
\par
It can be seen that in the simulation this algorithm behaves in the order O(N²) with increasing numbers of atoms N. It can be reduced to a linear order O(N) if we only consider atoms up to a certain distance (cutoff-distance) around each atom. This a good approximation as the forces get smaller as the interatomic distance between the atoms increases. The next goal is to generate a list containing the nearest atoms that are inside this cutoff-distance, which can be done by using domain decomposition \cite[cf.][]{molDymCourse}
\section{Berendsen-Thermostat}
\begin{comment}
- couple the moleclular system to a larger heat bath
- thermostat controls the heat of the simulation so the system does not melt or evaporate
\end{comment}
The initial state of the atomic system is often far away form the equilibrium. To prevent atoms from melting or evaporating, thermostats are used to control the heat/energy of the atoms. A rather simple thermostat, which was used in the simulation, is the Berendsen-thermostat.
\par
It is typically implemented by rescaling the velocities by a certain factor as shown in Eq.  \ref{coupelingFunction}. The factor is composed of the target-temperature $T_{0}$, the current temperature $T$, the timestep of the simulation $\Delta{t}$ and the relaxation time $\tau$.
\begin{equation}
	\label{coupelingFunction}
	\lambda = \sqrt{1 + \bigg(\frac{T_{0}}{T} -1\bigg)\frac{\Delta t}{\tau}}
\end{equation}
Reducing the temperature of the simulation via rescaling the velocities of each atom can be done because the temperature is connected to kinetic energy via the following equation \cite[cf.][]{molDymCourse}.
\begin{equation}
	\label{bolzmann}
	\frac{3}{2} k_{\mathrm{B}} T = \sum_{i} \frac{1}{2} m v_{i}^2
\end{equation}
With Eq. \ref{bolzmann} the current temperature can be calculated and put into Eq. \ref{coupelingFunction}.

\section{Embedded-Atom Method Potentials}
\begin{comment}
- describe Units
- better discribed in the course
- good model for metalic systems
- work with gold clusters

\end{comment}
Embedded atom-potentials are a good model for metallic bonding in solid or liquid states for different materials. The method used in the code was developed by Gupta \cite{gupta} and the parameters were taken from  Cleri \& Rosato \cite{rosato}.
\par
%TODO explain a bit
\begin{comment}
pair potentials cant model crystals as they have 3 independet elastic constants
put pair potentials have only two -> cauchy pressure
rather heuristic description in the lecture, like basic chemistry
E_pot = E_repulsion + E_embedding (embedding energy is connected to electric density)
E_repulustion is typically a pair potential
E_emedding is a funtiunal of the density in r
\end{comment}
Compared to pair potentials, the potential energy is calculated from two contributions shown in Eq. \ref{EAM-basic}. The first contribution $E_{repulsion}$ is modeled as a pair-potential. The second factor $E_{bonding}$ models the electron density between the metal atoms.
\begin{equation}
	\label{EAM-basic}
	E_{\mathrm{pot}}  = E_{\mathrm{repulsion}} + E_{\mathrm{bonding}}
\end{equation}

The Eqs. \ref{rosatto-repulsion} and \ref{rosatto-bonding} show how $E_{\mathrm{repulsion}}$ and $E_{\mathrm{bonding}}$ were implemented in the code. The parameter $A$,  $\xi$, $p$ and $q$ are also taken from the paper of Cleri and Rosato and can be fitted to different types of metals \cite{rosato}.
\begin{equation}
 	\label{rosatto-repulsion}
 	\mathrm{E}_{\mathrm{R}}^{i} = \sum_{j} A e^{-p(r_ij/r_{0} - 1)}
 \end{equation}

\begin{equation}
	\label{rosatto-bonding}
	%\mathrm{}_{}^{}
	\mathrm{E}_{\mathrm{B}}^{i} = - \big\{\sum_{j}\xi^{2} e^{-2q(r_{ij}/r_{0}-1)} \big\}^{1/2}
\end{equation}

To finalize the implementation, the forces between the atoms also have to be calculated. For this the Eq. \ref{potentialEquationAtoms} can be considered again. The expression has to be derived.


% !TeX root = ../assembly-lines-analysis-presentation.tex
% !TeX encoding = UTF-8
% !TeX spellcheck = en_GB

\section{Modelling and solution technique}
  \subsection{Evaluation of performance measures}
    \begin{frame}{Time To Done}
      \begin{equation*}
        \mbox{TTD}(k,\omega) := \left\{ \begin{array}{ll}
          \displaystyle \sum_{\gamma\in \phi_k} P_{k, \gamma,\omega} \cdot (R(k,\gamma) + Z(k,\gamma)), &  \mbox{ if } \sigma_k=\mbox{\em producing}
          \medskip\\
          \mbox{TTD}(k-1,\omega) + V(k), & \mbox{ if } \sigma_k=\mbox{\em idling}
          \medskip\\
          0, & \mbox{ if } \sigma_k=\mbox{\em done}
        \end{array} \right.
        \label{eq:ttd}
      \end{equation*}

      \begin{itemize}
        \item $P_{k,\gamma,\omega}$ probability weight that $\pl{WS}_k$ is in phase $\gamma$ according to $\omega$
        \item $R(k,\gamma)$ \textit{remaining time} in phase $\gamma$ of $\pl{WS}_k$
        \item $Z(k,\gamma)$ \textit{execution time} of phases of $\pl{WS}_k$ that follow $\gamma$
        \item $V(k)$ \textit{production time} of $\pl{WS}_k$
      \end{itemize}

      \begin{center}\hspace{-0.5cm}\scalebox{0.8}{\input{img/assembly_line_TTD}}\end{center}

      Backward recursive evaluation
    \end{frame}

    \begin{frame}{Time To Idle}
      \begin{equation*}
        \mbox{TTI}(k,\omega) := \left\{ \begin{array}{ll}
          \max\{\mbox{TTD}(k,\omega),\mbox{TTI}(k+1,\omega)\}, & \mbox{ if } \sigma_k\in\{\mbox{\em producing}, \mbox{\em done}\}
          \medskip\\
          0, & \mbox{ if } \sigma_k=\mbox{\em idling}
        \end{array} \right.
        \label{eq:tti}
      \end{equation*}

      \begin{itemize}
        \item $\mbox{TTI}(k,\omega)=\max\{ \mbox{TTD}(k,\omega), \ldots, \mbox{TTD}(k+n,\omega) \}$
        \begin{itemize}
          \item $\pl{WS}_j$ producing/done $\forall j \in [k,k+n]$
          \item either $\pl{WS}_{k+n}$ last workstation or $\pl{WS}_{k+n+1}$ idling
        \end{itemize}
        \item $\pl{WS}_k$ becomes idle when the bottleneck finishes its production
      \end{itemize}

      \begin{center}\hspace{-1.5cm}\scalebox{0.8}{\input{img/assembly_line_TTI}}\end{center}

      Forward recursive evaluation
    \end{frame}

    \begin{frame}{Time To Start Next}
      \begin{equation*}
        \mbox{TTSN}(k,\omega) := \max\{ \mbox{TTI}(k,\omega), \mbox{TTD}(k-1,\omega) \}
        \label{eq:ttn}
      \end{equation*}

      \vspace{1em}
      \begin{center}\hspace{-1.5cm}\scalebox{0.8}{\input{img/assembly_line_TTSN}}\end{center}

      Forward and backward recursive evaluation
    \end{frame}

  \subsection{Disambiguation of phases}
    \begin{frame}{Disambiguation of observed phases}
      Resolve observed (producing) phases' ambiguity
      \begin{itemize}
        \item steady-state probability that $\pl{WS}_k$ is in phase $\gamma$ according to $\omega$
      \end{itemize}
      Given observation $\phi_k$ for workstation $\pl{WS}_k$
      \begin{itemize}
        \item we compute probability $P_{k,\gamma,\omega}$
        \item that it was actually $\gamma$ that produced $\phi_k$
      \end{itemize}

     	\begin{equation*}
       	P_{k,\gamma,\omega} = \frac{\tilde{\pi}(\gamma)}{\displaystyle \sum_{\gamma' \in \phi_k} \tilde{\pi}(\gamma')}
       	\label{eq:probabilityObservation}
     	\end{equation*}

     	\begin{itemize}
       	\item $\tilde{\pi}(\gamma)$ steady-state probability of phase $\gamma$ in an isolated model of $\pl{WS}_k$
     	\end{itemize}
    \end{frame}

    \begin{frame}{Isolated workstation model}
      The isolated workstation model represents a workstation\\
      repeatedly processing a product
      \begin{itemize}
        \item one product being processed
        \item after its production, it's moved back to the entry point of the workstation
      \end{itemize}

      \begin{center}\scalebox{0.6}{\input{img/isolated_workstation}}\end{center}

      It can be used for two reasons
      \begin{itemize}
        \item steady-state probabilities of producing phases are independent
        \item the inspection is at steady-state
        \begin{itemize}
          \item arrivals and productions can be considerer in equilibrium
        \end{itemize}
      \end{itemize}
    \end{frame}

  \subsection{Remaining time}
    \begin{frame}{Remaining time}
      Evaluation of $F_{R(k,\gamma)}(t) = $ CDF of $R(k,\gamma)$
      \begin{itemize}
        \item $R(k,\gamma)$ \textit{remaining time} in phase $\gamma$ of $\pl{WS}_k$
      \end{itemize}

      \vspace{1em}
      Problem!
      \begin{itemize}
        \item remaining times of enabled GEN transitions are \textit{dependent}
        \item joint probabilities don't allow for a compositional approach
      \end{itemize}

      \vspace{1em}
      $\sfrac{1}{3}$ \textit{Immediate} approximation
      \begin{itemize}
        \item assume that phase $\gamma$ is inspected at its ending
        \begin{itemize}
          \item $\tilde{F}_{R(k, \gamma)}(t) = 1 \quad \forall t$
        \end{itemize}
        \item represents an \textit{upper bound}
      \end{itemize}

      \vspace{1em}
      $\sfrac{2}{3}$ \textit{Newly enabled} approximation
      \begin{itemize}
        \item assume that phase $\gamma$ is inspected at its beginning
        \begin{itemize}
          \item $\tilde{F}_{R(k, \gamma)}(t) = F_{\gamma}(t)$
          \item $F_{\gamma}(t)$ original CDF of the duration of $\gamma$
        \end{itemize}
        \item represents a \textit{lower bound}
      \end{itemize}
    \end{frame}

    \begin{frame}{Remaining time}
      $\sfrac{3}{3}$ \textit{Independent remaining times} approximation
      \begin{itemize}
        \item consider the remaining times of ongoing phases as \textit{independent}
        \item represents a (better) \textit{lower bound}
      \end{itemize}

      \begin{block}{Theorem: positive correlation \& stochastic order}
        If $\hat{R}$ is an independent version of vector $R$ of positively correlated remaining times of ongoing phases, then $\hat{R} \geq_{st} R$
      \end{block}

      \vspace{1em}
      Steady-state distribution of $\hat{R}(k,\gamma)$\\
      computed according to the Key Renewal Theorem\footnote{\scriptsize Serfozo, R., 2009. Basics of applied stochastic processes. Springer Science \& Business Media.}
      \begin{equation*}
        \tilde{F}_{R(k,\gamma)}(t) = \frac{1}{\mu} \int_{0}^{t} [1 - F_{\gamma}(s)]ds
      \end{equation*}
      \begin{itemize}
        \item $\mu$ expected value of $F_{\gamma}(t)$
      \end{itemize}
    \end{frame}

  \subsection{Execution and production time}
    \begin{frame}{Execution and production time}
      Evaluation of $F_{Z(k,\gamma)}(t)$ and $F_{V(k)}$
      \begin{itemize}
        \item $Z(k,\gamma)$ \textit{execution time} of phases of $\pl{WS}_k$ that follow $\gamma$
        \item $V(k)$ \textit{production time} of $\pl{WS}_k$
      \end{itemize}

      \vspace{1em}
      CDFs of $Z(k,\gamma)$ and $V(k)$ are computed as transient probabilities

      \begin{itemize}
        \item $F_{Z(k,\gamma)}$ transient probability from phase after $\gamma$ to final phase of $\pl{WS}_k$
        \item $F_{V(k)}$ transient probability from first phase to final phase of $\pl{WS}_k$
      \end{itemize}

      \vspace{2em}
      Upper/lower bounds for \textit{TTD}, \textit{TTI} and \textit{TTSN} can be evaluated
      \begin{itemize}
        \item \textit{convolution} and \textit{max} operations maintain stochastic order
      \end{itemize}
    \end{frame}


\documentclass{ximera}
\input{../preamble}
\title{Trigonometric Substitions}
%%%%%\author{Philip T. Gressman}

\begin{document}
\begin{abstract}
  We practice executing trigonometric substitutions.
\end{abstract}
\maketitle

\section*{(Video) Calculus: Single Variable}
\youtube{D_2N1OLQjyk}

\section*{Online Texts}
\begin{itemize}
\item \link[OpenStax II 3.3: Trigonometric Substitution]{https://openstax.org/books/calculus-volume-2/pages/3-3-trigonometric-substitution}
\item \link[Ximera OSU: Trigonometric Substitution]{https://ximera.osu.edu/mooculus/calculus2/trigonometricSubstitution/titlePage}
\item \link[Community Calculus 8.3: Trigonometric Substitution]{https://www.whitman.edu/mathematics/calculus_online/section08.03.html}
\end{itemize}

\section*{Examples}

\begin{example}
(c.f.~APEX Calculus Example 6.4.2) Compute the indefinite integral
\[ \int \frac{dx}{\sqrt{5 + x^2}}. \]
\begin{itemize}
\item The structure of this integrand is adapted to a trigonometric substitution of \wordChoice{\choice{secant}\choice{sine}\choice[correct]{tangent}} type, so we let $x = \sqrt{5} \answer{\tan \theta}$ (type out the word theta). This gives $dx = \sqrt{5} \answer{\sec^2 \theta}~d \theta$.
\item We use the identity $\sec^2 \theta = \tan^2 \theta + 1$, the quantity $5 + x^2$ can be rewritten using our substitution to equal $\answer{5 \sec^2 \theta}$. Therefore
\[ \int \frac{dx}{\sqrt{5+x^2}} dx = \int \answer{\sec \theta} \, d \theta = \answer{\ln | \sec \theta + \tan \theta|} + C. \]
(When writing out the indefinite integral, don't forget absolute values.)
\item We construct a reference triangle compatible with our substitution. In this case, that means we need a right triangle with an angle $\theta$ which satisfies $x/\sqrt{5} = \tan \theta$:
\begin{center}
\begin{image}
\includegraphics[width=4in]{images/trigsub02.png}
\end{image}
\end{center}
\item Using this reference triangle, we get that
\[ \tan \theta = \frac{x}{\sqrt{5}} \qquad \sec \theta = \answer{ \frac{\sqrt{x^2+5}}{\sqrt{5}}}. \]
Using these formulas, we can write
\[ \ln |\sec \theta + \tan \theta| = \ln \left| \answer{\frac{x}{\sqrt{5}} + \frac{\sqrt{x^2+5}}{\sqrt{5}}} \right| . \]
\item We conclude that
\[ \int \frac{dx}{\sqrt{x^2+5}} = \ln | x + \sqrt{x^2 + 5} | + C. \]
(Note that the factor of $\sqrt{5}$ in the denominator of the logarithm is not necessary when we already have an arbitrary constant $C$ in our answer.)
\end{itemize}
\end{example}

\begin{example}
Compute the indefinite integral
\[ \int \frac{dx}{x^2 \sqrt{x^2 - 3}}. \]
\begin{itemize}
\item The structure of this integrand is adapted to a trigonometric substitution of \wordChoice{\choice[correct]{secant}\choice{sine}\choice[correct]{tangent}} type, so we let $x = \sqrt{3} \answer{\tan \theta}$. This gives $dx = \sqrt{3} \answer{\sec \theta \tan \theta}~d \theta$.
\item We use the identity $\sec^2 \theta = \tan^2 \theta + 1$, the quantity $x^2 - 3$ can be rewritten using our substitution to equal $\answer{3 \tan^2 \theta}$. Therefore
\[ \int \frac{dx}{x^2 \sqrt{x^2 - 3}} = \int \answer{ \frac{\sqrt{3} \sec \theta \tan \theta}{3 \sec^2 \theta \sqrt{3} \tan \theta}} d \theta = \answer{\frac{\sin \theta}{3}} + C.\]
\item We construct a reference triangle compatible with our substitution. In this case, that means we need a right triangle with an angle $\theta$ which satisfies $x/\sqrt{3} = \sec \theta$:
\begin{center}
\begin{image}
\includegraphics[width=4in]{images/trigsub03.png}
\end{image}
\end{center}
\item Using this reference triangle, we get that
\[ \sin \theta = \answer{\frac{\sqrt{x^2-3}}{x}}.\]
\item We conclude that
\[ \int \frac{dx}{x^2 \sqrt{x^2-3}} = \answer{ \frac{\sqrt{x^2-3}}{3x}} + C. \]
\end{itemize}
\end{example}

\begin{example}
(c.f.~APEX Calculus Example 6.4.1) Compute the indefinite integral
\[ \int \sqrt{9 - x^2} dx. \]
\begin{itemize}
\item The structure of this integrand is adapted to a trigonometric substitution of \wordChoice{\choice{secant}\choice[correct]{sine}\choice{tangent}} type, so we let $x = 3 \answer{\sin \theta}$. This gives $dx = 3 \answer{\cos \theta}~d \theta$.
\item Using the identity $\cos^2 \theta + \sin^2 \theta = 1$, the expression $9 - x^2$ can be rewritten using the formula above as $\answer{(3 \cos \theta)^2}$. Therefore
\[ \int \sqrt{9-x^2} dx = \int \answer{9 (\cos \theta)^2} d \theta. \]
\item We use the power reduction formula $\cos^2 t = (1 + \cos 2t)/2$ and conclude
\[ \int \sqrt{9-x^2} dx = \frac{9}{2} \int \left( 1 + \cos 2 \theta \right) d \theta = \frac{9}{2} \left[ \theta + \frac{1}{2} \sin 2 \theta \right] + C. \]
\item Now we construct a reference triangle which is compatible with the substitution we made. In this case, this means we need a right triangle for which $x/3 = \sin \theta$:
\begin{center}
\begin{image}
\includegraphics[width=4in]{images/trigsub01.png}
\end{image}
\end{center}
\item Using the reference triangle above, we have the identities
\[ \sin \theta = \frac{x}{3} \qquad \cos \theta = \answer{ \frac{\sqrt{9-x^2}}{3}} \qquad \theta = \arcsin \frac{x}{3}. \]
\item The quantity $\sin 2 \theta$ is difficult to write as a function of $x$ as it stands, so we first use the double-angle formula $\sin 2 \theta = \cos \theta \sin \theta$. We therefore conclude that
\[ \int \sqrt{9-x^2} dx = \answer{ \frac{9}{2} \left( \arcsin \frac{x}{3} + \frac{x \sqrt{9-x^2}}{9} \right)} + C. \]
(Note: Ximera will interpret $\sin^{-1} x$ as $1/(\sin x)$, so write $\arcsin$ when you mean inverse sine.)
\end{itemize}
\end{example}

\end{document}


\documentclass[aps,pra,notitlepage,amsmath,amssymb,letterpaper,12pt]{revtex4-1}
\usepackage{amsthm}
\usepackage{graphicx}
\graphicspath{{./CW1LaTeXimages/}}

\newenvironment{problem}[2][Problem]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
\newenvironment{solution}{\begin{proof}[Solution]}{\end{proof}}

% --------------------------------------------------------------
%                   Document Begins Here
% --------------------------------------------------------------

\begin{document}

\title{Homework 1: Remarks on Derivatives}
\author{Alexis \surname{Ford}}
\author{Nengyin (Helen) \surname{Zhu}}
\affiliation{CS 510 -- Computing for Scientists}
\date{\today}

\begin{abstract}
	This paper will give an overview of the derivative, namely, the definition of the derivative of a function, as well as what it means to take the derivative of a function.
\end{abstract}

\maketitle

\section{Definition}
The derivative of a function $f(x)$, denoted $f'(x)$, is defined as
\begin{equation}
f'(x)=\lim_{h\rightarrow0}\frac{f(x+h)-f(x)}{h}.
\end{equation}
In words, the derivative is the instantaneous rate of change of a function $f(x)$ at $x$, but let us take a more intuitive look. Notice that $\frac{f(x+h)-f(x)}{h}$ bears a strong resemblnce to the formula used to find the slope, $m$, of a line defined by two points, $(x, y)$ and $(x_1,y_1)$:
\begin{equation}
m=\frac{y_1-y}{x_1-x}.
\end{equation}
If we say $h=x_1-x$, and $f(x)$ is the function such that $f(x)=y$ and $f(x_1)=y_1$, we need only note that $h=x_1-x\Rightarrow x_1=x+h$ before the two fractions become identical. Thus, what the derivative is really doing, is finding a slope.

It is easy enough to find a slope given two points, $a$ and $b$, and we can even estimate the slope of a nonlinear function at a particular point $x$ by creating a secant line using points around our point of interest. The derivative, however, is far more clever than that. By takig the limit as the distance between $a$ and $b$ approaches $0$, we can get the exact, instantaneous rate of change at our point $x$. That is, we get the slope of the line tangent to $f(x)$ at $x$.

\section{An Illustration}
Let us take a look at some pictures to get a better idea of what exactly is going on. Consider the function $f(x)=\frac{1}{10}(x^4-10x^2+9)$, and say we want to find the slope of this function at $x=2$. Let us start by looking at an approximation of the slope using a secant line through the points $(1,0)$ and $(3,0)$.

\begin{figure}[h!]
  \includegraphics[width=0.4\textwidth]{horizSec}
  \caption{Secant using points $a=1$ and $b=3$, yielding the blue, horizontal line.\\ (Image created in WinPlot by Alexis Ford)}
  \label{fig:fig1}
\end{figure}

We can easily calculate (and see) that the slope of out blue secant line is $0$. If we move our points closer to $x=2$, say $a=1.5$ and $b=2.5$, we can see that the slope is closer to what we imagine our tangent line's slope should be (we can calculate the slope to be roughly $-1.69$), but we can get closer still.

\begin{figure}[h!]
  \includegraphics[width=0.4\textwidth]{closerSec}
  \caption{Secant using points $a=1.5$ and $b=2.5$, yielding the blue line.\\ (Image created in WinPlot by Alexis Ford)}
  \label{fig:fig2}
\end{figure}

By taking the derivative, which forces our two points as close together as possible, we get our exact tangent line, $f'(2)=-\frac{4}{5}$

\begin{figure}[h!]
  \includegraphics[width=0.4\textwidth]{tangent}
  \caption{A red tangent line at $x=2$ with slope $f'(2)=-\frac{4}{5}$.\\ (Image created in WinPlot by Alexis Ford)}
  \label{fig:fig3}
\end{figure}

\section{Conclusion}
Derivatives are a powerful tool, be sure not to drink and derive.
\end{document}

%%% INSTRUCTOR COMMENTS %%%
%
%  Very thorough! Hopefully you can use these notes when teaching calculus next.
%  LaTeX is a wonderful thing for creating professional-looking documents.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%


\subsection{Hotelling's lemma}