\documentclass[10pt, oneside, letterpaper]{article}
\usepackage[margin=1in]{geometry}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\definecolor{mygreen}{rgb}{0,0.6,0}
\definecolor{mygray}{rgb}{0.5,0.5,0.5}
\definecolor{mymauve}{rgb}{0.58,0,0.82}
\usepackage{listings}
\lstset{
  backgroundcolor=\color{white}, % choose the background color
  basicstyle=\footnotesize\ttfamily, % size of fonts used for the code
  breaklines=true, % automatic line breaking only at whitespace
  frame=single, % add a frame
  captionpos=b, % sets the caption-position to bottom
  commentstyle=\color{mygreen}, % comment style
  escapeinside={\%*}{*)}, % if you want to add LaTeX within your code
  keywordstyle=\color{blue}, % keyword style
  stringstyle=\color{mymauve}, % string literal style
}
\usepackage{enumitem}
\usepackage{blindtext}
\usepackage{datetime2}
\usepackage{fancyhdr}
\usepackage{amsmath}
\usepackage{arydshln} % dash line package for matrices
\usepackage{mathtools}
\usepackage{float}
\usepackage{pgf}

\title{Numerical Oscillasations of Discretizations Rules}
\author{Assignment 7}
\date{Due: 2021/04/05}

\pagestyle{fancy}
\setlength{\headheight}{23pt}
\setlength{\parskip}{1em}
\fancyhf{}
\chead{Assignment 7 \\ Numerical Oscillasations of Discretizations Rules}
\rhead{Michel Kakulphimp \\ Student \#63542880}
\lhead{EECE560 \\ UBC MEng}
\cfoot{\thepage}

\begin{document}
\maketitle
\thispagestyle{fancy}

\section{Introduction}

In this assignment, we are investigating the response of different discretization rules to step and ramp inputs. We can observe interesting behaviours, such as numerical oscillations, by using these inputs. These stimuli represent a sudden change in value, which will generate distinct responses in different LTI systems. For this assignment, the response of the system gives us an idea of how stable the discretization rule is. The subject for this exercise is a lossless first order system in the form of a voltage source connected in series to a capacitor. At time $t=0$, a switch is closed and the voltage source applies its input to the system: the step or a ramp. The resulting current in the system is what we observe as the output, which provides us with the behaviour we wish to investigate and comment on.

\section{Setup}

\begin{figure}[H]
  \centering
  \includegraphics[width=1.5in]{capacitor.png}
  \caption{Voltage and current relationship of a capacitor}
  \label{capacitor}
\end{figure}

Shown in Figure \ref{capacitor} is the circuit representation of a capacitor, a fundamental electrical component which stores energy as electrical charge when a voltage is applied to it. This process is encouraged by the geometry of its conductive plates and the properties of the the dielectric sandwiched between them. As a result, it resists changes in voltage applied to it. The relationship of the current flowing through it and the voltage across its terminals is as follows:

\begin{alignat}{2}
  i_c(t) = C\frac{dv_c(t)}{dt}
\end{alignat}

We see that current is a result of a differentiation of the voltage applied to the capacitor, multiplied by a constant C, the capacitance in units of Farads. When we discretize this relationship, our derivation is performed over a time step of $\Delta{}t$ instead of $dt$, so in a not so rigorous mathematical way, we can rearrange the formula as follows:

\begin{alignat}{2}
  i_c(t)\frac{dt}{C} &= dv_c(t) \\
  i_c(t)\frac{\Delta{}t}{C} &\simeq dv_c(t)
\end{alignat}

For discretizations which approximate the derivative, we will be using this relationship.

If we rearrange the original capacitance equation so that $i_c(t)$ is the independent variable and $v_c(t)$ is the dependent variable, then we get the following relationship:

\begin{alignat}{2}
  v_c(t) = \frac{1}{C}\int{i_c(t)dt}
\end{alignat}

Now we see that if current is the input, the voltage across the capacitor's terminals is a result of the integration of the current passing through it multiplied by the reciprocal of the capacitance. We can discretize this integration by evaluating the integral over the interval of $t - \Delta{}t$ and $t$, which results in the following relationship:

\begin{alignat}{2}
  C\left[v_c(t)-v_c(t-\Delta{}t)\right] &= \int_{t-\Delta{}t}^{t}i_c(t)dt \\
  C\left[v_c(t)-v_c(t-\Delta{}t)\right] &\simeq \text{approximated area of integration}
\end{alignat}

For discretization which approximates the integral, we will be using this relationship.

The following sections demonstrate how each of the discretization rules have been used to approximate the response of an ideal capacitance. The trapezoidal, backward Euler, and forward Euler discretizations approximate an area (an integration), and Gear's second order approximates a derivative. The relationships found in Equations 3 and 6 will be used to evaluate the results in this assignment along with the respective discretization technique. A Z-transform is also performed in order to obtain the poles of the $z^{-1}$ transfer function in order to comment on the observed behaviour in the results.

\subsection{Trapezoidal Derivation}

The trapezoidal discretization approximates an integral through an area. The process of obtaining the current through a trapezoidal discretized capacitor is shown below.

\begin{alignat}{2}
  \text{approximated area of integration} &\simeq C\left[v_c(t)-v_c(t-\Delta{}t)\right] \\
  \text{trapezoidal area} &= \frac{i_c(t) + i_c(t-\Delta{}t)}{2} \\
  \frac{i_c(t) + i_c(t-\Delta{}t)}{2} &= C\left[v_c(t)-v_c(t-\Delta{}t)\right] \\
  \Aboxed{i_c(t) &= \frac{2C}{\Delta{}t}v_c(t) - \frac{2C}{\Delta{}t}v_c(t-\Delta{}t) - i_c(t-\Delta{}t)}
\end{alignat}

A Z-transform can be applied to the discretized function to infer its behaviour. The derivation is shown below:

\begin{alignat}{2}
  i_c(t) &= \frac{2C}{\Delta{}t}v_c(t) - \frac{2C}{\Delta{}t}v_c(t-\Delta{}t) - i_c(t-\Delta{}t) \\
  I_c(z) &= \frac{2C}{\Delta{}t}V_c(z) - \frac{2C}{\Delta{}t}z^{-1}V_c(z) - z^{-1}I_c(z) \\
  I_c(z) + z^{-1}I_c(z) &= \frac{2C}{\Delta{}t}\left[V_c(z) - z^{-1}V_c(z)\right] \\
  I_c(z)(1 + z^{-1}) &= \frac{2C}{\Delta{}t}V_c(z)(1 - z^{-1}) \\
  \Aboxed{Y_c(z) &= \frac{I_c(z)}{V_c(z)} = \frac{2C}{\Delta{}t}\frac{(z - 1)}{(z + 1)}}
\end{alignat}

\subsection{Backward Euler Derivation}

The backward Euler discretization approximates an integral through an area. The process of obtaining the current through a backward Euler discretized capacitor is shown below.

\begin{alignat}{2}
  \text{approximated area of integration} &\simeq C\left[v_c(t)-v_c(t-\Delta{}t)\right] \\
  \text{Backward Euler area} &= i_c(t)\Delta{}t \\
  \Aboxed{i_c(t) &= \frac{C}{\Delta{}t}\left[v_c(t)-v_c(t-\Delta{}t)\right]}
\end{alignat}

A Z-transform can be applied to the discretized function to infer its behaviour. The derivation is shown below:

\begin{alignat}{2}
  i_c(t) &= \frac{C}{\Delta{}t}\left[v_c(t)-v_c(t-\Delta{}t)\right] \\
  I_c(z) &= \frac{C}{\Delta{}t}\left[V_c(z)-z^{-1}V_c(z)\right] \\
  \Aboxed{Y_c(z) &= \frac{I_c(z)}{V_c(z)} = \frac{C}{\Delta{}t}\frac{(z - 1)}{z}}
\end{alignat}

\subsection{Forward Euler Derivation}

The forward Euler discretization approximates an integral through an area. The process of obtaining the current through a forward Euler discretized capacitor is shown below. In order to get the function in terms of $i_c(t)$, we need to shift the function over $+\Delta{}t$ which results in the function looking forward to obtain its data.

\begin{alignat}{2}
  \text{approximated area of integration} &\simeq C\left[v_c(t)-v_c(t-\Delta{}t)\right] \\
  \text{Forward Euler area} &= i_c(t-\Delta{}t)\Delta{}t \\
  i_c(t-\Delta{}t) &= \frac{C}{\Delta{}t}\left[v_c(t)-v_c(t-\Delta{}t)\right] \\
  & \text{shift time }+\Delta{}t \\
  \Aboxed{i_c(t) &= \frac{C}{\Delta{}t}\left[v_c(t+\Delta{}t)-v_c(t)\right]}
\end{alignat}

A Z-transform can be applied to the discretized function to infer its behaviour. The derivation is shown below:

\begin{alignat}{2}
  i_c(t) &= \frac{C}{\Delta{}t}\left[v_c(t+\Delta{}t)-v_c(t)\right] \\
  I_c(z) &= \frac{C}{\Delta{}t}\left[zV_c(z) - V_c(z)\right] \\
  I_c(z) &= \frac{C}{\Delta{}t}V_c(z)(z - 1) \\
  \Aboxed{Y_c(z) &= \frac{I_c(z)}{V_c(z)} = \frac{C}{\Delta{}t}\frac{z(z - 1)}{z}}
\end{alignat}

\subsection{Gear's Second Order Derivation}

\begin{alignat}{2}
  dv_c(t) &\simeq i_c(t)\frac{\Delta{}t}{C} \\
  \text{derivative approximation} &= \frac{3}{2}\left[v_c(t) - \frac{4}{3}v_c(t-\Delta{}t) + \frac{1}{3}v_c(t-2\Delta{}t)\right] \\
  i_c(t)\frac{\Delta{}t}{C} &= \frac{3}{2}\left[v_c(t) - \frac{4}{3}v_c(t-\Delta{}t) + \frac{1}{3}v_c(t-2\Delta{}t)\right] \\
  \Aboxed{i_c(t) &= \frac{3C}{2\Delta{}t}\left[v_c(t) - \frac{4}{3}v_c(t-\Delta{}t) + \frac{1}{3}v_c(t-2\Delta{}t)\right]}
\end{alignat}

A Z-transform can be applied to the discretized function to infer its behaviour. The derivation is shown below:

\begin{alignat}{2}
  i_c(t) &= \frac{3C}{2\Delta{}t}\left[v_c(t) - \frac{4}{3}v_c(t-\Delta{}t) + \frac{1}{3}v_c(t-2\Delta{}t)\right] \\
  I_c(z) &= \frac{3C}{2\Delta{}t}\left[V_c(z) - \frac{4}{3}z^{-1}V_c(z) + \frac{1}{3}z^{-2}V_c(z)\right] \\
  Y_c(z) &= \frac{I_c(z)}{V_c(z)} = \frac{3C}{2{}\Delta{}t}\frac{z^{2} - \frac{4}{3}z + \frac{1}{3}}{z^{2}} = \frac{3C}{2\Delta{}t}\frac{(z - 1)(z - \frac{1}{3})}{z^{2}} \\
  \Aboxed{Y_c(z) &= \frac{I_c(z)}{V_c(z)} = \frac{3C}{2\Delta{}t}\frac{(z - 1)(z - \frac{1}{3})}{z^{2}}}
\end{alignat}

\subsection{Evaluating Voltage Stimuli}

With all of our derivations in hand, we can now apply the step and ramp stimuli to a capacitor and observe the current response of the system. Shown in Figure \ref{circuit} is the circuit that is used for this assignment. It consists of a voltage source connected in series with a capacitor, which is discretized using the techniques outlined in the previous sections. A switch is used to close the circuit at $t=0$ which applies the voltage to the capacitor.

\begin{figure}[H]
  \centering
  \includegraphics[width=2in]{assignment_circuit.png}
  \caption{Circuit being evaluated in this assignment}
  \label{circuit}
\end{figure}

Each of the different discretization functions were calculated step-by-step to obtain their solution using the help of a table. The results section provides both the voltage input function (step or ramp) alongside the current output response using the specific discretization method.

In order to obtain the plots shown in this assignment, a Python script was written to generate the plots using values of 1 where a constant was required (e.g. $C$ or $\Delta{}t$) and the plot labels were modified to reflect their values in terms of $C$ and $\Delta{}t$ instead of a numerical value.

\section{Results}

The following section contains all of the plots required by the assignment. The assignment requests that the ramp input only be applied to the trapezoidal and backward Euler discretizations. Since the Python script made the generation of the plots an easy task, the ramp response was plotted for all discretization methods for completeness.

\begin{figure}[H]
  \begin{center}
    \input{trapezoidal_step.pgf}
  \end{center}
  \caption{Capacitor Trapezoidal Discretization Step Response}
  \label{trap_step}
\end{figure}

\begin{figure}[H]
  \begin{center}
    \input{trapezoidal_ramp.pgf}
  \end{center}
  \caption{Capacitor Trapezoidal Discretization Ramp Response}
  \label{trap_ramp}
\end{figure}

\begin{figure}[H]
  \begin{center}
    \input{backward_euler_step.pgf}
  \end{center}
  \caption{Capacitor Backward Euler Discretization Step Response}
  \label{back_step}
\end{figure}

\begin{figure}[H]
  \begin{center}
    \input{backward_euler_ramp.pgf}
  \end{center}
  \caption{Capacitor Backward Euler Discretization Ramp Response}
  \label{back_ramp}
\end{figure}

\begin{figure}[H]
  \begin{center}
    \input{forward_euler_step.pgf}
  \end{center}
  \caption{Capacitor Forward Euler Discretization Step Response}
  \label{forward_step}
\end{figure}

\begin{figure}[H]
  \begin{center}
    \input{forward_euler_ramp.pgf}
  \end{center}
  \caption{Capacitor Forward Euler Discretization Ramp Response}
  \label{forward_ramp}
\end{figure}

\begin{figure}[H]
  \begin{center}
    \input{gears_second_order_step.pgf}
  \end{center}
  \caption{Capacitor Gear's Second Order Discretization Step Response}
  \label{gear_step}
\end{figure}

\begin{figure}[H]
  \begin{center}
    \input{gears_second_order_ramp.pgf}
  \end{center}
  \caption{Capacitor Gear's Second Order Discretization Ramp Response}
  \label{gear_ramp}
\end{figure}

\newpage
\section{Discussion}

The following section contains the discussion elements required by the assignment as well as additional conclusions drawn from the assignment.

\begin{itemize}
    \item Using the poles of the $z^{-1}$ transfer function, we can explain some of the observed behaviour of the step function to the approximation.
    \begin{itemize}
      \item Trapezoidal: $Y_c(z) = \frac{2C}{\Delta{}t}\frac{(z - 1)}{(z + 1)}$
        \begin{itemize}
          \item Pole at $-1$: stable integrator that will exhibit bounded oscillations at discontinuities
          \item Zero at $1$: stable differentiator
          \item We use trapezoidal as an integrator so we observe the poles of the transfer function. We observe that both the step and ramp response exhibit bounded oscillations. Both the step and ramp function represent discontinuities in the input of the system.
        \end{itemize}
      \item Backward Euler: $Y_c(z) = \frac{C}{\Delta{}t}\frac{(z - 1)}{z}$
        \begin{itemize}
          \item Pole at $0$: Stable integrator that is critically damped
          \item Zero at $1$: Stable differentiator
          \item We use backward Euler as an integrator so we observe the poles of the transfer function. We can confirm that the response is indeed critically damped as there is no overshoot in the response when a step is applies to the system.
        \end{itemize}
      \item Forward Euler: $Y_c(z) = \frac{C}{\Delta{}t}(z - 1) = \frac{C}{\Delta{}t}\frac{z(z - 1)}{z}$
        \begin{itemize}
          \item Pole at $0$: Stable integrator that is critically damped
          \item Zeros at $0$ and $1$: Stable differentiator that is critically damped
          \item We use forward Euler as an integrator so we observe the poles of the transfer function. We can confirm that the response is indeed critically damped as there is no overshoot in the response when a step is applies to the system.
        \end{itemize}
      \item Gear's Second Order: $Y_c(z) = \frac{3C}{2\Delta{}t}\frac{(z - 1)(z - \frac{1}{3})}{z^{2}}$
        \begin{itemize}
          \item Poles at $0$ and $0$: Stable integrator that is critically damped
          \item Zeros at $1$ and $\frac{1}{3}$: Stable differentiator
          \item We use Gear's as a differentiator so we want to look at the zeros of the transfer function. We observe that the both the step and ramp response of Gear's second order is underdamped but settles into a steady-state, which implies its stability. The zeros obtained in the z-transform confirm this.
        \end{itemize}
    \end{itemize}
    \item Numerical oscillations were present in the trapezoidal discretization, which indicate that it may not be very suitable for use in simulations where sudden changes occur (such as a breaker opening). If an event like this is detected, the simulation should switch to a discretization method that will not oscillate, such as Backward or Forward Euler.
    \item Gear's second order exhibits an oscillation that quickly dissipates, indicating an  underdamped response. It seems to settle into the correct steady-state within a $\Delta{}t$. It is feasible that this small oscillation could cause unintended behaviours in the circuit being simulated. It definitely isn't as pervasive as a trapezoidal discretization, so it would be a better choice for large changes than it.
    \item An interesting thing to note is that the steady-state response to a ramp input observed in the discretizations all settle on the capacitance $C$ (trapezoidal averages to C). This technique of applying a constant voltage ramp to a capacitor such that the current drawn by it is constant is a method to extract the capacitance C ($C = I_{constant}\frac{\Delta{}t}{\Delta{}V}$).
\end{itemize}

% \newpage
% \section{Code Listings and Data}

% \subsection{Python Code Listing}
% \label{code-listing-python}
% The following is the code written in Python to generate the plots used in this report.
% \lstinputlisting[language=Python]{assignment6.py}

\end{document}


\section{Sensitivity Analysis}

An important aspect of any fuel cycle transition scenario
is the accrual of fissile materials for new reactor deployment.
The collaborative strategy makes a transition possible
from the perspective of material availability,
but the aggressive transition demands a significant increase in reprocessing capacity.

We explored the impact of two key variables, the lifetime of French \glspl{LWR} and the
breeding ratio of \gls{ASTRID} reactors. The range over which we varied these parameters (table \ref{tab:sen_par})
sought to capture the full span of their uncertainty.

Note that \gls{ASTRID} breeding ratios are arbitrarily increased
by direct adjustment of their output fuel compositions. We did not
take into account the other reactor parameters (e.g. core size, initial
fuel composition, fuel residence time, etc.)
that would be neccessary to achieve a higher breeding ratio. More detailed analyses
of the reactor physics and their effect on this transition scenario
should be pursued in future work.

\begin{table}[h]
    \centering
    \caption{Both \gls{LWR} lifetime and \gls{ASTRID} breeding ratio impact
    transitional reprocessing demand.}
    \begin{tabularx}{\textwidth}{lrr}
        \hline
        \textbf{Parameter} & \textbf{Default} & \textbf{Values} \\
        \hline
        Breeding Ratio of \glspl{ASTRID} & 1.08 & 1.11, 1.15, 1.18 \\
        Lifetime of French \glspl{LWR} [years] & 60  & 65, 70, 80 \\
        \hline
    \end{tabularx}
    \label{tab:sen_par}
\end{table}

\subsection{Breeding Ratio}

Increase in the breeding ratio of \gls{ASTRID} reactors
decreases the total reprocessing demand, since less
\gls{UNF} must be reprocessed to extract the same amount of
plutonium. Additionally,
\glspl{ASTRID} become independent more quickly due to
higher breeding of plutonium.

Figure \ref{fig:br_fuel} shows the relationship between breeding ratio and fuel loading in \glspl{ASTRID}.
The \glspl{ASTRID} produce
more plutonium, reducing the plutonium demand from
reprocessed \gls{UOX}. However, since \gls{LWR} \gls{UNF} is not
the limiting factor for this transition scenario,
increasing the breeding ratio does not play a significant
role in the transition scenario, especially considering the technical difficulty
in achieving a high breeding ratio.

\begin{figure}[!ht]
	\centering
	\subfloat{\includegraphics[width=.45\textwidth]{./images/sensitivity/108br.png}}\quad
	\subfloat{\includegraphics[width=.45\textwidth]{./images/sensitivity/111br.png}}\\
	\subfloat{\includegraphics[width=.45\textwidth]{./images/sensitivity/115br.png}}\quad
	\subfloat{\includegraphics[width=.45\textwidth]{./images/sensitivity/118br.png}}
	\caption{\gls{ASTRID} fuel loading patters are altered by changes in \gls{ASTRID}
		breeding ratio. Less \gls{ASTRID} fuel comes from reprocessed \gls{LWR} \gls{UNF}
		because \glspl{ASTRID} generate more plutonium.}
	\label{fig:br_fuel}
\end{figure}

The sensitivity analysis also shows, as demonstrated in figure \ref{fig:br_uox} that
increasing the breeding ratio decreases the mass of \gls{LWR} \gls{UNF}
required for the transition.

\begin{figure}[htbp!]
    \begin{center}
        \includegraphics[scale=0.6]{./images/sensitivity/br_uox_unf_cum.png}
    \end{center}
    \caption{Sensitivity analysis demonstrates that increasing the breeding
    ratio decreases the required \gls{UOX} \gls{UNF}. }
    \label{fig:br_uox}
\end{figure}

The differential impacts of varying the breeding ratios are
shown in table \ref{tab:br_diff}. The differences were calculated
using the following equation:

\[ \epsilon = \frac{(x - x_{base})}{x_{base}} \cdot 100 \]

\begin{table}[h]
	\centering
        \caption{Breeding ratio impact on reprocessing requirements.}
	\begin{tabular}{lrrrr}
		\hline
                & \multicolumn{4}{c}{\% Difference} \\
		\textbf{Breeding Ratio $\longrightarrow$}& \textbf{1.08}& \textbf{1.11} & \textbf{1.15} & \textbf{1.18} \\
		\hline
		Total reprocessing demand & 0.0 & -5.3 & -7.8 & -10.3 \\
		\gls{LWR} \gls{UNF} reprocessed & 0.0  & -4.8 & -7.2 & -9.6 \\
		\hline
	\end{tabular}
	\label{tab:br_diff}
\end{table}

\subsection{Lifetime Extension of French \glspl{LWR}}\label{sec:life}
Extending the lifetime of French \glspl{LWR} lowers the average
monthly \gls{UOX} reprocessing demand, since the \gls{ASTRID} deployment becomes
delayed (shown in figure \ref{fig:pow_diff}). The plutonium demand is delayed,
 allowing the reprocessing plant more time to prepare plutonium for \gls{ASTRID} reactors.

\begin{figure}[htbp!]
    \begin{center}
        \includegraphics[scale=0.7]{./images/sensitivity/pow_ratio.png}
    \end{center}
    \caption{The ratio of \glspl{ASTRID} to \glspl{LWR} in France demarcates
    the transition period.}
    \label{fig:pow_diff}
\end{figure}

Figure \ref{fig:ext_fuel} shows the change in \gls{ASTRID} fuel loading with
\gls{LWR} lifetime extension. The \gls{ASTRID} fuel loaded with plutonium
from \gls{LWR} \gls{UNF} conveys the corresponding \gls{LWR} \gls{UNF} reprocessing demand.
The change in \gls{ASTRID} deployment alters \gls{ASTRID} fuel loading patterns.
However, increasing the \gls{LWR} lifetimes
does not increase the \gls{LWR} \gls{UNF} demand significantly (less than 1\%
for the 20-year extension case),
because \glspl{ASTRID} become self-sustaining at similar times after the first
\gls{ASTRID} deployment.

\begin{figure}[!ht]
	\centering
	\subfloat{\includegraphics[width=.45\textwidth]{./images/sensitivity/base.png}}\quad
	\subfloat{\includegraphics[width=.45\textwidth]{./images/sensitivity/5yr.png}}\\
	\subfloat{\includegraphics[width=.45\textwidth]{./images/sensitivity/10yr.png}}\quad
	\subfloat{\includegraphics[width=.45\textwidth]{./images/sensitivity/20yr.png}}
	\caption{\gls{ASTRID} fuel loading patterns are altered by changes in \gls{ASTRID} deployment
			 caused by the lifetime extension of \glspl{LWR}.}
	\label{fig:ext_fuel}
\end{figure}

The quantitative effects of
\gls{LWR} lifetime extensions are shown in table \ref{tab:ext_met}.
The differences were calculated using the same equation used for the
breeding ratio study.
Since \gls{LWR} lifetime extensions shorten the span of \gls{ASTRID} operations, less \gls{ASTRID} fuel is needed when \gls{LWR} lifetimes are extended.
Therefore, it is not fair to compare the mass of total \gls{UNF} reprocessed,
since less plutonium is extracted from \gls{UNF}. Instead, we compared the
average reprocessing values and the total amount of \gls{LWR} \gls{UNF} reprocessed.
There is not a significant difference (less than $1\%$ for the 20-year extension case)
in the amount of \gls{LWR}
\gls{UNF} reprocessed. The delay in \gls{ASTRID} deployment
spreads out the \gls{LWR} \gls{UNF} reprocessing demand,
thereby dramatically reducing ($39\%$ for the 20-year extension case)
the average monthly \gls{LWR} \gls{UNF} reprocessing demand.

\begin{table}[h]
	\centering
	\caption{\gls{LWR} lifetime extension impact on reprocessing requirements.}
	\begin{tabular}{lrrrr}
		\hline
		& \multicolumn{4}{c}{\% Difference} \\
		\textbf{\gls{LWR} lifetime extension $\longrightarrow$}& \textbf{0 years}& \textbf{5 years} & \textbf{10 years} & \textbf{20 years} \\
		\hline
		Total \gls{ASTRID} fuel produced & 0.0 & -3.9 & -8.0 & -16.3 \\
		\gls{LWR} \gls{UNF} reprocessed & 0.0  & -0.7 & -0.7 & -0.7 \\
		Average \gls{LWR} \gls{UNF} reprocessed & 0.0 & -16.0 & -25.7 & -39.8 \\
		Average \gls{UNF} reprocessed & 0.0 & -2.3 & -4.2 & -8.3 \\
		\hline
	\end{tabular}
	\label{tab:ext_met}
\end{table}


% declare document class and geometry
\documentclass[12pt]{article} % use larger type; default would be 10pt
\usepackage[margin=1in]{geometry} % handle page geometry

\input{../header2.tex}

\title{Phys 220A -- Classical Mechanics -- Lec05}
\author{UCLA, Fall 2014}
\date{\formatdate{16}{10}{2014}} % Activate to display a given date or no date (if empty),
         % otherwise the current date is printed

\begin{document}
\setlength{\unitlength}{1mm}
\maketitle

% begin Pauline's notes

\section{More on constraints}

If we have readily dependent constraints sometimes they can be reduced to holonomic constraints. For example with a wheel rolling without slipping we have a coordinate $x(t)$ which describes the center position of the wheel. We also have the orientation of the angle. Here we have the constraint of rolling without slipping which couples our things
\begin{equation}
\d{x}{t} + R\d{\phi}{t} = 0
\end{equation}
This is an integrable constraint because they are integrable
\begin{equation}
\d{}{t} (x + R\phi)
\end{equation}
So that it is independent of time.

More generally if we have coordinates
\begin{equation}
\sum_i = \psi_i(q) \dot{q_i} = 0
\end{equation}
In general these are not integrable. But if
\begin{equation}
\phi_i = \pd{\phi}{q_i}
\end{equation}
Then the constraint is equivalent to
\begin{equation}
\d{}{t} \phi(q_1) = \sum_i \pd{\phi}{q_i} \dot{q_i}
\end{equation}
Then the velocity dependent constraint can be replaced by the holonomic constraint. However this is only in a small class of problems. Even in a simple example with a wheel that rotates around and rolls without slipping with its axis fixed to $x = 0$. Then we have coordinates $\theta$ and $\phi$. Then our condition of rotating without slipping is in the direction to the radius in the direction $\theta$
Our constraint then is
\begin{equation}
\dot{x} = r\dot{\phi} \sin \theta
\end{equation}
\begin{equation}
\dot{y} = -r \dot{\phi} \cos\theta
\end{equation}
This is not integrable because $\theta$ is dependent on time.

\section{Symmetries, conserved charges and Noether's theorem}

Let's go one step up in abstraction, we'll introduce the notion of symmetry in Lagrangian mechanics. One of the beautiful results of Noether's theorem, which in and of itself is not impressive, is [something that he didn't finish the sentence what]. Basically it allows us to simplify a problem. For example what does it mean when a pen is axisymmetric? It means that we have something invariant under a transformation (such as rotation). What is an active or passive transformation? Rotation vs rotating your axes.

Either way under these transformation if we something that doesn't change under it then the quantity associated with the transformation is symmetric. Symmetries that are not subject to Noether's theorem is discrete symmetry, so parity and charge conjugation.

Symmetry is one of the most important concepts in physics.
\begin{itemize}
\item It brings in the powerful mathematics of group theory.
\item It allows us to impose order in confusing structures, e.g. $SU(2)$ for isospin, $SU(3)$ for eightfold for nuclear resonances. For example particle in the 60s produced a lot of nuclear resonances. Every week they'd fine a new particle with no way that they'd fit together. However, symmetry made that into an ordered structure. The dynamics were governed by this symmetry
\item The crown jewel, \textbf{Noether's theorem}: tells us that continuous symmetries give us a conservation law which gives us accounting in experiments. Basically what comes in has to come out. Gives us a way of checking things.
\item Aesthetically pleasing (But must be careful!) [i.e. it's fucking beautiful]
\item Spontaneous breaking of symmetry is a very important concept, for example in phase transitions, Higgs mechanism
\end{itemize}

Before we go into a derivation of the general Noether theorem, let's start with some simple observations.

%%%% commented out. original from Wickes' notes
\begin{comment}
\subsection{Adding a derivative to the Lagrangian}

What happens if you add a total time derivative of a function $\Lambda(q(t), t)$ to the Lagrangian? So
\begin{eqn}
L' = L(q, \dot q, t) + \od{}{t} \Lambda(q(t), t).
\end{eqn}
We find that answers to the EL equations do not change:
\begin{eqn}
\pd{L'}{q} - \od{}{t} \pd{L'}{\dot{q}} = \pd{L}{q} - \od{}{t} \pd{L}{\dot{q}} + \left\{ \pd{}{q} \left[ \pd{\Lambda}{q} \dot{q} + \pd{\Lambda}{t} \right] - \od{}{t} \pd{}{\dot{q}} \left[ \pd{\Lambda}{q} \dot{q} + \pd{\Lambda}{t} \right] \right\}
\end{eqn}
and we see that the derivatives of $\Lambda$, the terms in the braces, cancel one another, leaving us with the EL equations for $L'$.
\end{comment}
%%%% end comment

\section{Perturbing the Lagrangian}

When you consider a Lagrangian and perturb it by
\begin{equation}
  L'(q, \dot{q}, t) = L(q, \dot{q}, t) + \d{\Lambda(q, t)}{t}
\end{equation}
Not going to touch the coordinates
\begin{equation}
\pd{L'}{q} - \d{}{t} \pd{L'}{\dot{q}} = \pd{L}{q} - \d{}{t} \pd{L}{\dot{q}} - \pd{}{q} \left( \pd{\Lambda}{q} \dot{q} + \pd{\Lambda}{t}\right) - \d{}{t} \pd{}{\dot{q}} \left( \pd{\Lambda}{q} \dot{q} + \pd{\Lambda}{t}\right)
\end{equation}
The final two terms should be zero since we're only perturbing it by a time derivative
\begin{equation}
0 = \pd[2]{\Lambda}{q} \dot{q} + \md{\Lambda}{2}{t}{}{q}{} + \d{}{t} \pd{\Lambda}{q}
\end{equation}
This should be obvious because of the time derivative will not change the action

We have an important equivalence. Consider a particle coupled to an EM field
\begin{equation}
L = \frac{1}{2} m\v{x}^2 - e\Phi - e\dot{x} \v{A}
\end{equation}
Under gauge transformation
\begin{equation}
L' = L + e\pd{\Lambda}{t} + e\dot{x} \nabla \Lambda = e \d{}{t} \Lambda
\end{equation}
This gives us equivalent Lagrangians.

\section{Obvious Conservation Laws}
Some conservation laws are very easy to derive directly from the Euler Lagrange coordinates. It is especially easy for \textit{cyclic coordinates}. A coordinate $q_i$ is called cyclical if and only if its derivative $\dot{q_i}$ appears in the Lagrangian and not $q$ itself, so $\pd{L}{q_i} = 0$. This leads to a conserved quantity
\begin{equation}
Q = \pd{L}{\dot{q_i}}
\end{equation}
For a cyclic coordinate $q$, under the transformation $q' = q + \epsilon$ the Lagrangian has \textit{exactly} the same form. This is different from general coordinate transformations where we have the same Lagrangian just written in different coordinates; instead the Lagrangian remains exactly the same, written in the \textit{same} coordinates.

\setcounter{example}{0}
\begin{example}
Flat direction in potential
\begin{equation}
L = \frac{1}{2} m \dot{x_1}^2 + \frac{1}{2} m\dot{x_2}^2 + V(x_1)
\end{equation}
This implies that $m\dot{x_2}$ is conserved.
\end{example}

\begin{example}[Central potential]
In the potential, $\phi$ is cyclic and so angular momentum is conserved
\end{example}

\begin{example}
If $L(q, \dot{q})$ has no explicit time dependence then the Hamiltonian is conserved. Since we have,
\begin{equation}
H = \pd{L}{\dot{q}} \dot{q} - L
\end{equation}
we find
\begin{equation}
\d{H}{t} = \d{}{t} (\pd{L}{\dot{q}} \dot{q}) - \d{L}{t} = \d{}{t} \pd{L}{\dot{q}} \dot{q} - \pd{L}{q} \dot{q} = 0.
\end{equation}
\end{example}

\section{General Lessons}
We have symmetry whenever we have something continuous. In the first example with the flat direction, it's saying that if we shift it along the flat part then it's not changing. In the case of the central force it just means if we rotate the system it's the same. the final just means that we can make a shift in the time coordinate. If I shift the time coordinate the form of the Lagrangian is constant. There's a continuous symmetry under which the Lagrangian does not change.

The second lesson is that to show that a quantity is conserved I need to use the Euler-Lagrange equation. The important thing is here is that the first part does not need Euler Lagrange equation, that symmetry is independent of the Euler Lagrange equation.

% End Pauline's notes. Begin Wickes' notes

%\section{Cyclic coordinates}

%For a cyclic coordinate $q$, i.e. $L(q,\dot q)$ only depends on $\dot q$,, under the transformation $q' = q + \epsilon$ the Lagrangian has \textit{exactly} the same form. This is different from general coordinate transformations where we have the same Lagrangian just written in different coordinates; instead the Lagrangian remains exactly the same, written in the original coordinates.

The general definition of a continuous symmetry of the Lagrangian is a transformation
\begin{eqn}
q'_i(t, \epsilon) = q_i (t) + \epsilon \delta q_i (q,t).
\end{eqn}
which leaves the Lagrangian unchanged up to a total derivative, i.e.
\begin{eqn}
L(q', \dot{q}', t) - L(q, \dot q, t) = \od{\Lambda}{t}.
\end{eqn}
which can be expanded as
\begin{eqn}
\cancel{L(q, \dot q, t)} + \pd{}{\epsilon} \eval{L(q, \dot q, t)}_{\epsilon = 0} - \cancel{L(q, \dot q, t)} = \od{\Lambda}{t}.
\end{eqn}

Thus most generally a symmetry is a transformation $q_i \rightarrow q'_i = q_i + \epsilon \delta q_i$ such that
\begin{eqn}
\pd{}{\epsilon} \eval{L(q, \dot q, t)}_{\epsilon = 0} = \od{\Lambda}{t}.
\end{eqn}
Then \textbf{Noether's theorem} states that given such a symmetry we have a conserved quantity
\begin{eqn}
Q = \sum_i \pd{L}{\dot q_i} \delta q_i - \Lambda.
\end{eqn}

We can prove this by showing that $\od{Q}{t} = 0$. We have
\begin{align}
\od{\Lambda}{t} &= \eval{\pd{L}{\epsilon}}_{\epsilon = 0} = \sum_i \left( \pd{L}{q_i} \delta q_i + \pd{L}{\dot q_i} \od{}{t} \delta q_i \right) \\
	&= \sum_i \left( (\od{}{t} \od{L}{\dot q_i} ) \delta q_i + \pd{L}{\dot q_i} \od{}{t} \delta q_i \right),
\end{align}
which we can rewrite to find
\begin{eqn}
\od{Q}{t} = \od{}{t} \left( \sum_i \pd{L}{\dot q_i} \delta q_i - \Lambda \right) = 0.
\end{eqn}
QED.

\setcounter{example}{0}
\begin{example}
For a cyclic variable, we have $\delta q_i = \delta_i^1 \implies \pd{L}{\dot q_1} = Q$.
\end{example}

\begin{example}
For a free particle, we have $L = \sum_i (1/2) m_i \dot {\v x}_i^2$. Here our symmetry is translation, so the conserved quantity is $\v{Q} = \sum_i m_i \dot{\v x}_i$ which is just the momentum.
\end{example}

\begin{example}
For $\delta \v x_i = \v \omega \times \v x_i$, we have a conserved quantity
\begin{eqn}
Q = \sum_i m_i \dot{\v x}_i \cdot (\v \omega \times \v x_i) = \v \omega \cdot \sum_i m_i (\v x_i \times \dot{\v x}_i) = \v \omega \cdot \v L_\text{total}
\end{eqn}
so the total angular momentum is conserved.
\end{example}

\subsection{Time translations}

Consider the change $t \rightarrow t + \epsilon$. Then we can write
\begin{eqn}
q'(t, \epsilon) = q(t + \epsilon) = q(t) + \epsilon \dot q_i + \bigo(\epsilon^2)
\end{eqn}
so under time translation we have $\delta q = \dot q$. So we have
\begin{eqn}
\eval{ \pd{L}{\epsilon} }_{\epsilon = 0} = \od{L}{t} - \pd{L}{t},
\end{eqn}
so this is only a symmetry if there is no explicit time dependence, in which case we have $\Lambda = L$. Furthermore we can calculate $Q$:
\begin{eqn}
\sum_i \pd{L}{\dot q_i} \dot q_i - L = H.
\end{eqn}
The conserved quantity is just the Hamiltonian!

\subsection{Pathological issues}

In general for our action
\begin{eqn}
S[q] = \int dt L(q, \dot q, t)
\end{eqn}
this doesn't necessarily work [?]. The most general definition of a symmetry involves reparametrization of time:
\begin{eqn}
\begin{matrix}
q'_i (t', \epsilon) & = & q_i (t) & + & \epsilon \delta q_i(q, t) \\
t' & = & t & + & \epsilon \delta t (q,t),
\end{matrix}
\end{eqn}
and we have
\begin{eqn}
\int_{t'_1}^{t'_2} dt' L(q', \dot q', t') = \int_{t_1}^{t_2} dt L(q, \dot q, t) + \int dt \od{\Lambda}{t}
\end{eqn}
with a conserved quantity
\begin{eqn}
Q = \pd{L}{\dot q_i} \delta q_i - \Lambda + (L - \pd{L}{\dot q_i} \dot q_i) \delta t.
\end{eqn}

For example, with a Lagrangian
\begin{eqn}
L = (1/2) m \dot q^2 - \alpha / 2 q^2
\end{eqn}
we have a few conserved quantities. For one, the energy
\begin{eqn}
H = (m/2) \dot q^2 + \alpha / 2 q^2,
\end{eqn}
and furthermore we can write
\begin{eqn}
t' = \frac{\alpha t + \beta}{\gamma t + \delta}, \qquad q' (t') = \frac{q(t)}{\gamma t + \delta}
\end{eqn}
where $M = \begin{pmatrix} \alpha & \beta \\ \gamma & \delta \end{pmatrix}$ has determinant 1. Then we have new conserved quantities
\begin{align}
D &= -(m/2) q \dot q + t((m/2) \dot q^2 + \alpha / 2 q^2), \\
K &= (m/2) (\dot q t - q)^2 + (\alpha / 2 q^2) t^2.
\end{align}

\end{document}


\begin{refsection}
\chapter{The Three-Terminal Black Box}

\section*{Objectives}

\begin{enumerate}
\item To study a three-terminal black box and identify the circuit within it along with the values of the electronic components.

\item To understand the responses of different active and passive circuit elements and their combinations, and to learn to recognise them.

\item To exercise your deductive and inductive powers, much as real physicists must do with real experiments.
\end{enumerate}

\section*{Introduction}

You are given a sealed box with three terminals marked $A$, $B$, and $C$ which connect to a circuit inside. This circuit consists of \textbf{three} electronic components of different kinds, arranged between the three terminals in either a ``star'' or ``delta'' connection, as shown in Figure (\ref{fig:bb}). You are expected to identify each component's type, value, and orientation with respect to the terminals.

\begin{figure}[!htb]
    \centering
    \includegraphics[scale=0.3]{figs/bb.png}
    \caption{Different configurations possible within a blackbox: it will be specified if the box contains a star (\textit{left}) or delta (\textit{right}) connection. Do not attempt to open the box! }
    \label{fig:bb}
\end{figure}

\begin{imp}
You will be told beforehand if the connection is ``star'' or ``delta'' as you cannot distinguish them otherwise. This is because, if the circuit contains only resistors, every star connection has an equivalent delta connection and vice versa.

The black box will always contain \textbf{three} electronic components, but they need not all be distinct. Some components may be repeated; a black box may be composed of (i) three resistors, (ii) two resistors and a diode, (iii) a battery and two diodes, and so on. Each arm (see Figure (\ref{fig:bb})) may contain anything from all to none of the components.
\end{imp}

\subsection*{Star and Delta Connections}

Standard 3-component circuits take on two major forms with names that represent the way in which the components are connected: a \textbf{Star} sometimes represented by Y, and a Delta connected network sometimes represented by a triangle or $\Delta$.

\begin{figure}[!htb]
       \begin{subfigure}[t]{0.3\textwidth}
				\centering
                \includegraphics[scale=0.4]{bb-comp.png}
                \captionsetup{justification=centering}
                \caption{Component or combination \\of components}
       \end{subfigure}%
       \begin{subfigure}[t]{0.3\textwidth}
				\centering
                \includegraphics[scale=0.4]{bb-star.png}
                \caption{Star connection}
        \end{subfigure}%
        \begin{subfigure}[t]{0.3\textwidth}
        		\centering
                \includegraphics[scale=0.4]{bb-delta.png}
                \caption{Delta connection}
        \end{subfigure}%
        \caption{In a star connection, one node is inaccessible and so only two components are connected at any time. In a delta connection, all the components are connected.}
        \label{fig:starAndDelta}
\end{figure}

\begin{figure}[!htb]
\centering
\includegraphics[scale=0.4]{figs/bb-starToDelta.png}
\caption{Every star connection has an \textit{equivalent} delta connection. If the components happen to be resistors, explicit formulae may be derived for each arm.}
\label{fig:starToDelta}
\end{figure}

 Both these forms, represented in Figure (\ref{fig:starAndDelta}), are indistinguishable from each other, in that for every star connection there is an equivalent delta connection (with different values for the individual components) and vice versa. It is for this reason that you must keep in mind what form circuit in the black box has before drawing any conclusions.

\begin{imp}
If all the components are resistances, the following formulae will allow you to move between a star connection and its associated delta connection and vice versa:

\begin{minipage}{0.5\textwidth}
\centering
\paragraph*{Delta to Star Network:}
\begin{equation*}
\begin{aligned}
P &= \frac{A B}{A + B + C}\\
Q &= \frac{A C}{A + B + C}\\
P &= \frac{B C}{A + B + C}\\
\end{aligned}
\end{equation*}
\end{minipage}
\begin{minipage}{0.5\textwidth}
\centering
\paragraph*{Star to Delta Network:}
\begin{equation*}
\begin{aligned}
A &= \frac{P Q + Q R + R P}{R}\\
B &= \frac{P Q + Q R + R P}{Q}\\
C &= \frac{P Q + Q R + R P}{P}\\
\end{aligned}
\end{equation*}

\end{minipage}

\end{imp}

\subsection*{Passive circuit components}

Passive circuit components are electrical components that cannot control the current in a circuit. They do not generate energy, but instead dissipate or store it.

\begin{description}
\item[Resistors] A resistor is an electronic component used to oppose or limit the current in a circuit. It's behaviour is dictated by Ohm’s law, which states that the voltage applied across the terminals of a resistor is directly proportional to the current flowing through it, with the constant of proportionality called the \textit{resistance}, $V=IR$.

% \begin{equation*}
% V = I R
% \end{equation*}

\item[Capacitors]

A capacitor, made from two conductive plates with an insulator between them, stores electrical energy in the form of an electric field. It blocks DC signals (when fully charged) and allows the AC signals to pass through it. The charge stored in a capacitor is given by $Q=CV$.

% \begin{equation*}
% Q = CV
% \end{equation*}

When used with a resistor, the time a capacitor takes to charge or discharge is measured in units of an intrinsic time scale, known as the time constant $\tau = RC$ of the circuit.

\end{description}

\subsection*{Active circuit components}
An active device is any type of circuit component with the ability to electrically control electron flow in the circuit.

\begin{description}
\item[Batteries]

Charges can be separated to produce a voltage. A battery uses a chemical reaction to produce energy and separate opposite sign charges onto its two terminals. As the charge is drawn off by an external circuit, doing work and finally returning to the opposite terminal, more chemicals in the battery react to restore the charge difference and the voltage.

\item[p-n junction Diodes]

These are two-terminal semiconductor devices, which allow the electric current in only one direction while blocking it in the reverse direction. A diode has an anode (or positive end) containing positive charge carriers called ``holes'', and a cathode (or negative end) containing negative charge carriers (electrons). The interface between these ends forms a region without any charge carriers called the \textbf{depletion layer}.

The process of applying the external voltage to a p-n junction semiconductor diode is called biasing. If the diode is \textbf{forward biased} -- that is, when a positive voltage is applied to the anode and a negative voltage to the cathode -- it allows the charge carriers, and hence current, to flow. On the other hand, if the diode is \textbf{reverse biased} -- negative to the anode and positive to the cathode -- it blocks the current flow. In the conventional symbol for a diode, the arrowhead indicates the conventional direction of electric current when the diode is forward biased.

\begin{figure}[!htb]
\centering
\includegraphics[scale=0.4]{figs/diode_characteristics.png}
\caption{A diode and its current-voltage characteristics: for small (positive) values of input voltage, the output current varies exponentially.}
\label{fig:diodeChar}
\end{figure}

Unlike a resistor, a diode does not behave linearly with respect to the applied voltage as the diode has an exponential current-voltage (I-V) relationship and therefore cannot be described by simply using an equation such as Ohm’s law. The reason for this is that the width of the depletion layer decreases with increase in positive voltage. After a certain ``knee'' voltage (0.3 V for Germanium semiconductors and 0.7 V for Silicon semiconductors) the width of the barrier effectively goes to zero, and the diode acts like a short circuit with zero resistance. When a junction diode is reverse biased the thickness of the depletion region increases and the diode acts like an open circuit blocking any current flow (except for a very small leakage current), until an ``avalanche'' voltage when the device undergoes a breakdown and gets shorted, leading to maximum current flow in the \textit{opposite} direction.

\end{description}

\section*{Experimental Setup}

\subsection*{Apparatus}

\begin{enumerate}
\item A black box with three connecting terminals marked $A$, $B$, and $C$
\item A variable DC power supply (\textit{Keltronix})
\item Two digital multimeters (\textit{MECO 603})
\item A signal generator (\textit{Testronix 72})
\item A Digital Storage Oscilloscope (\textit{GW INSTEK–GDS-1102U})
\item A digital stopwatch (\textit{Racer})
\item A resistor ladder
\item Connecting wires

\end{enumerate}

\subsection*{Description}

\begin{description}
\item[Digital Multimeter (\textit{MECO 603})]

A multimeter is an instrument used to measure multiple parameters like voltage, current, and resistance. In this experiment you will use the given digital multimeters (Model \textit{MECO - 603}) \textbf{\textit{only}} for the measurement of DC and AC voltage and current. You will have to use input sockets marked COM, V/$\Omega$ and mA (or 20A) for the required measurements. Note that there are two input sockets marked mA and 20A for the current measurement. The socket marked mA may be used for measuring current below 250 mA and socket marked 20A may be used for measuring current up to 20 A. You will have to select the appropriate function and the range using the rotary switch provided on the multimeter. The value of voltage or current is displayed on the LCD screen. The multimeter is turned off by turning the dial to the appropriate setting.

\item[Variable DC Power Supply (\textit{Keltronix})]

The DC Variable Power Supply can either act as a source of constant voltage (CV), or constant current (CC), indicated by the two LEDs present on it. We will be using it as a constant voltage source, so make sure the CV LED is lit. An ideal voltage source is one that produces a fixed voltage irrespective of the current the load (your circuit) demands of it. Of course, this is not realistic; the supply given to you can supply a maximum potential difference of 15V, and a maximum current of 1A.

The voltage and the current in the circuit can be changed using the three knobs: voltage coarse, voltage fine, and current. The given power supply also displays the values of the output voltage and current. Do not use these values since the multimeter will be more reliable.

If the current knob is set to maximum, the supply acts as a constant voltage source. The constant voltage it supplies can be varied using the voltage knobs, and is independent of the load (your circuit) attached to it.\footnote{Similarly, if the voltage knob is set to maximum, the supply acts as a constant current source.}

\begin{imp}
If the current your circuit draws at any voltage is beyond 1A, the power supply will not be able to supply it. This could happen if you short the two terminals of the power supply (don't!) or if you are close to the knee voltage of a diode (as in this case, the circuit has effectively zero resistance). In this case, the power supply's LED will shift from CV to CC, indicating that it is providing the maximum current possible. Avoid this situation, as it could damage the power supply.
\end{imp}

\item[Signal Generator (\textit{Testronix 72})]

A signal generator is used to generate simple repetitive waveforms in the form of an alternating electrical wave. Typically, it will produce simple waveforms like sine, square, and triangular waves, and will allow you to adjust the frequency and amplitude of these signals. The instrument given to you generates sine and square waveforms. The output may be taken from the respective output sockets. The frequency can be adjusted by turning the dial and selecting the appropriate Frequency Multiplier button. For example, turning the dial to 3 and selecting the 10k button would provide an output waveform with a frequency of 30kHz. Similarly the amplitude switch, used in conjunction with the appropriate buttons, can be used to adjust the amplitude of the output waveform from 0V to 30V.

\end{description}

\subsection*{Precautions}

\begin{itemize}
\item The use of a multimeter to measure the resistance is strictly prohibited.
\item Do not try to open the black box, use only terminals $A$, $B$, and $C$ for the connections.
\item Passing more current through the multimeter's (250 mA or 20A) sockets than they can handle will cause its fuses to burn out, leading to an open circuit. Use an appropriate resistance to limit the current in the circuit. The current should not exceed 500 mA.
\item \textbf{Do not} short the outputs of the power supply, it could damage the equipment.

\item When drawing circuit diagrams use the standard symbols.
\item The digital multimeter, the DC power supply or the signal generator should be turned off if not in use.

\end{itemize}

\section*{Procedure}

\subsection*{Part A}

The black box will contain only combinations of resistors, p-n junction diodes, and batteries in a \textit{\textbf{star}} connection.

\begin{question}
    \paragraph{Question:} Since not all of the elements will necessarily be present in a box, which is the first element you will test for?
    \end{question}

\begin{enumerate}
    \item Choose the first element that you would like to detect (or eliminate), and design a method to do this.

    \item Repeat this for all the components.

    \begin{question}
    \paragraph{Question:} How could you tell which way a diode was oriented?

    \paragraph{Question:} How would you differentiate between a diode and a resistor?
\end{question}

    \item Give your answer in the form of a circuit diagram showing the terminals $A$, $B$, and $C$ clearly.
\end{enumerate}

\begin{tip}
You will need to give \textit{all} the information required in order to reconstruct the circuit. For example, you will need to determine the values of the resistors, the orientation of the diodes, and the voltage and orientation of the battery, if any of the above are used in the circuit.
\end{tip}

\begin{imp}
Clearly report the procedural steps you have taken with reference to (i) your complete plan of experiment, (ii) the data you will collect, (iii) how the collected data will be analysed and (iv) how your analysis will be interpreted. Your reporting should be comprehensive, and all important steps should be mentioned in your answer sheet.
\end{imp}

\subsection*{Parts B, C, \& D \textit{(optional)}}

\begin{itemize}
    \item \textbf{Part B:} The black box will contain only combinations of resistors, p-n junction diodes and capacitors in a \textit{\textbf{star}} connection.

    \item \textbf{Part C:} The black box will contain only combinations of resistors, p-n junction diodes, and batteries in a \textit{\textbf{delta}} connection.

    \item \textbf{Part D:} The black box will contain only combinations of  resistors, capacitors, and inductors in a \textit{\textbf{star}} connection.
\end{itemize}

% \subsection*{Part C \textit{(optional)}}
% The black box will contain only combinations of resistors, p-n junction diodes, and batteries in a \textit{delta} connection.

% \subsection*{Part D \textit{(optional)}}
% The black box will contain only combinations of  resistors, capacitors, and inductors in a \textit{star} connection.

\section*{References}

% \begin{enumerate}

% \item \href{https://www.elprocus.com/major-electronic-components/}{Overview of Various Basic Electronics Components.} Retrieved June 28, 2019, from \nolinkurl{https://www.elprocus.com/major-electronic-components/}

% \item \href{https://www.electronics-tutorials.ws/dccircuits/dcp_10.html}{Star Delta Transformation.} Retrieved June 28, 2019, from \nolinkurl{https://www.electronics-tutorials.ws/dccircuits/dcp_10.html}

% \item \href{https://www.electronics-tutorials.ws/diode/diode_3.html}{Electronics Tutorials: PN Junction Diode.} Retrieved June 28, 2019, from \nolinkurl{https://www.electronics-tutorials.ws/diode/diode_3.html}

% \end{enumerate}

\nocite{khaparde_training_2008}
\nocite{noauthor_pn_2013}
\nocite{noauthor_relationship_2013}
\nocite{noauthor_star_2013}
\nocite{noauthor_beginners_2013}
\nocite{noauthor_rc_2013}
\nocite{noauthor_electronic_2014}
\printbibliography[heading=none]

\newpage
\end{refsection}


\section*{Grading and Grading Policy}\label{sec:grading}

Your course grade will be calculated based on the percentages as follows:

\begin{table}[h]
\centering
\begin{tabular}{l|l}
Homework & 20\% \\
Midterm Examination I & 20\%\\
Midterm Examination II & 20\%\\
Final Examination & 35\% \\
Class participation & 5\%
\end{tabular}
\end{table}
\FloatBarrier

The semester is split into three periods :

\begin{enumerate}
\item From the beginning until midterm I. Midterm I covers material during this time..
\item From midterm I to midterm II. Midterm II covers material in this period only.
\item From midterm II until the final. The final is cumulative and covers all course material.
\end{enumerate}

Each of the periods is assessed evenly. Thus, each period must count the same towards your grade. Since there is 75\% of the grade allotted to exams, there is 25\% allotted to each period. Thus, the final is upweighted towards the material covered in the third period. In summary, the final will have 5/35 points $\approx$ 14\% for the first period's material, 5/35 points $\approx$ 14\% for the second period's material and 25/35 points $\approx$ 71\% for the last period's material. A good strategy for the final is to just study the material after Midterm II and minimal studying for the previous material.


\documentclass[12pt,letterpaper,twoside]{article}

\usepackage{cme212}

\begin{document}

{\centering \textbf{Paper Exercise 0 -- C++ Warm-up\\ Due Tuesday, January 15th in class} \par}
\vspace*{-8pt}\noindent\rule{\linewidth}{1pt}

\paragraph{Question 0: Lecture 0} The poor ampersand (\&) and asterisk (*) get used in a lot of different ways in C++. Given the following declaration and initialization for {\tt a}, {\tt b}, and {\tt c}:
\begin{verbatim}
int a = 2, b = -3, c = -7;
\end{verbatim}
\vspace{-1ex}
What can you say about the values of the following variables {\tt d} through {\tt h}:
{\small
\begin{cpp}
int* d = &c;
int& e = a;
int f  = b*c;
int g  = *&a;
int* h = a;
\end{cpp}
}

\vspace{-2ex}
\paragraph{Question 1: Lecture 0} What is the output of the program below? Explain in your own words why.
\begin{cpp}
#include <iostream>
int f(int& a, int& b) {
  a = 3;
  b = 4;
  return a + b;
}
int main() {
  int a = 1, b = 2;
  int c = f(a, a);  // Not a typo: calling f() with both arguments set to 'a'.
  std::cout << a << b << c << std::endl;
}
\end{cpp}

\vspace{-2ex}
\paragraph{Question 2: Lecture 0} What is the output of the program below, and why?  Recall: \href{https://en.cppreference.com/w/cpp/language/initializer_list}{member initializer lists}.
{\small
\begin{cpp}
#include <iostream>
struct A {
  A() : val(2) {}
  A(int v) : val(v+2) { v += 2; }
  A(A& a) : val(a.val+2) { a.val += 2; }
  int val;
};
int main(int argc, char** argv) {
  A a1;
  A a2(5);
  A a3(a1.val);
  A a4 = a3;
  std::cout << a1.val << a2.val << a3.val << a4.val << std::endl;
}
\end{cpp}
}
\paragraph{Question 2: Lecture 0}
For each of the following code snippets state if they will work and why/why not.
\begin{cpp}
	const int val = 9;
	int* ptr = &val;
	*ptr = 2;
\end{cpp}

\begin{cpp}
	int val = 9;
	const int* ptr = &val;
	*ptr = 2;
\end{cpp}
\begin{cpp}
	const int val1 = 9;
	const int* ptr = &val1;
	const int val2 = 8;
	ptr = &val2;
\end{cpp}
\begin{cpp}
	const int val1 = 9;
	int* const ptr = &val1;
	const int val2 = 8;
	ptr = &val2;
\end{cpp}

\begin{cpp}
	int val = 9;
	const int* ptr = &val;
	std::const_cast<int*> ptr = 2;
\end{cpp}

\begin{cpp}
	const int val = 9;
	const int* ptr = &val;
	std::const_cast<int*> ptr = 2;
\end{cpp}

\paragraph{Question 3: Lecture 0}
Why does the following code not work? Modify the \texttt{Student} class so the code does work.

\begin{cpp}
	class Student
	{
		int ID_ = 10;
		public:
			int getID(){return this->ID_;}
	}

	int main()
	{
		const Student Alex;
		std::cout<<Alex.getID()<<std::endl;
	}
\end{cpp}

\paragraph{Question 4: Lecture 1}
Rewrite the following code so you can find the bug when someone gives an invalid index for the \texttt{vector}. Using
\begin{enumerate}
	\item A \texttt{print} statement.
	\item An \texttt{assert} statement.
	\item A macro.
	\item A pause statement.
\end{enumerate}

\begin{cpp}
	double access_vec(std::vector<double> vec, unsigned int idx){
		return vec[idx];
	}
\end{cpp}

\end{document}


\documentclass[12pt]{article}
\usepackage{graphics}
\newcommand{\kg}{\mathrm{kg}}
\newcommand{\m}{\mathrm{m}}
\newcommand{\s}{\mathrm{s}}
\renewcommand{\deg}{\mathrm{deg}}
\newcommand{\km}{\mathrm{km}}
\newcommand{\cm}{\mathrm{cm}}
\newcommand{\mps}{\m\,\s^{-1}}
\newcommand{\mpss}{\m\,\s^{-2}}
\newcommand{\kgpmmm}{\kg\,\m^{-3}}
\newcommand{\N}{\mathrm{N}}
\newcommand{\J}{\mathrm{J}}
\newcommand{\Npmm}{\N\,\m^{-2}}
\newcommand{\tv}[1]{\mathbf{\vec{#1}}}
\newcommand{\dd}{\mathrm{d}}
\newcommand{\cell}[1]{\texttt{{#1}}}
\newcounter{problem}
\addtolength{\oddsidemargin}{-1in}
\addtolength{\textheight}{\headheight}
\setlength{\headheight}{0in}
\addtolength{\textheight}{\headsep}
\setlength{\headsep}{0in}
\setlength{\marginparwidth}{2in}
\begin{document}

\section*{NYU Physics 1---midterm exam}

Thursday 2009 October 15 in lecture.

\section*{Name:}

~ \vfill ~

\clearpage

\paragraph{Problem~\theproblem:}\refstepcounter{problem}%
The Moon is (1/80) the mass of the Earth.  If the compositions are
similar, what is the approximate radius of the Moon?  Give your answer
in units of $\km$.  State your assumptions and show your work
explicitly.

~ \vfill ~

\paragraph{Problem~\theproblem:}\refstepcounter{problem}%
In lecture we considered a car sliding around a banked circular turn
at constant speed, in the absence of friction.  Now imagine that the
car has static friction acting for transverse forces (that is,
opposing sliding up or down the bank) with a coefficient of $0.2$.
Draw the free-body diagram for the car---show only the forces and
their directions and approximate magnitudes---when it is going around
the turn at the maximum speed at which the car can go without sliding
uphill or downhill.  If you need to assume anything, state your
assumptions explicitly.

~ \vfill ~

\clearpage

\paragraph{Problem~\theproblem:}\refstepcounter{problem}%
Compute the velocity of the Space Shuttle in its orbit around the
Earth in units of $\mps$.  Show your calculation.  Assume the shuttle
is orbiting very close to the surface of the Earth (not a bad
approximation, as we discussed in class).  If you need to assume
anything else, state your assumptions explicitly.

~ \vfill ~

\paragraph{Problem~\theproblem}\refstepcounter{problem}%
A block of mass $m$ sits on an inclined plane, inclined at an angle
$\theta = 20\,\deg$ to the horizontal.  If the coefficient of friction
is $\mu = 0.9$ and the acceleration due to gravity is $g$, What is the
magnitude of the frictional force on the block, in terms of the
symbols given?  If you need to assume anything, state your assumptions
clearly.

~ \vfill ~

\clearpage

\paragraph{Problem~\theproblem:}\refstepcounter{problem}%
Imagine a particle of mass $m$ moving back and forth in the $x$
direction according to the equation
\begin{equation}
x(t)= A\,\cos\left(\omega\,t\right) \quad .
\end{equation}
What is the $x$-direction force as a function of time $F_x(t)$?

~ \vfill ~

\paragraph{Problem~\theproblem:}\refstepcounter{problem}%
What formulae should go into cells \cell{E9} and \cell{F9} in this
spreadsheet, which is integrating a trajectory?  State your formulae
in terms of the cell numbers (such as ``\cell{I8}''), not variables
(such as ``$a_x$''). \\
\resizebox{\textwidth}{!}{\includegraphics{../xls/exam.eps}}

~ \vfill ~

\clearpage

\paragraph{Problem~\theproblem:}\refstepcounter{problem}%
In lecture, I swung a full cup of iced tea in a vertical loop over my
head, like a roller coaster doing a loop-de-loop.  Explain, in
\emph{50 words or less} why the iced tea did not fall out when the cup
was upside-down.

~ \vfill ~

\end{document}


\documentclass[12pt]{article}
\usepackage{graphicx}
\usepackage{listings}
\usepackage{fullpage}
\usepackage{tikz}
\usepackage{enumitem}
\usetikzlibrary{shapes,arrows,calc,automata}

\lstset{ %
language=Java,
basicstyle=\small \ttfamily,commentstyle=\scriptsize\itshape,showstringspaces=false,breaklines=true,numbers=left}

\usepackage{fontspec}
\setmonofont{Cousine}[Scale=MatchLowercase]

\begin{document}

\title{Software Testing, Quality Assurance \& Maintenance (ECE453/CS447/SE465): Midterm}
\author{}
\renewcommand{\today}{}
\maketitle

 ~\\[-7em]

\begin{center}
{\Large February 17, 2017}
\end{center}

This open-book midterm has 5 questions and 80 points. Answer the
questions in your answer book. You may consult any printed material
(books, notes, etc).

\section*{Question 1: Test Design (10 points)}
I've included below some test code from bukkit's {\tt
  BukkitMirrorTest}.  Split this test into well-designed independent
subtests. I recommend 5 tests; use your judgment to decide what the
subtests should be. Write out the valid JUnit test cases after
splitting. You may write e.g. ``// L4'' to indicate that you are
including line 4 from the provided code. Write a sentence explaining
the benefits of splitting the test.

\begin{lstlisting}[basicstyle=\scriptsize \ttfamily]
  @Test
  public void bunchOfTests() throws Throwable {
      assertThat(Modifier.isStatic(bukkit.getModifiers()), is(true));
      assertThat(bukkit.isAnnotationPresent(Deprecated.class), is(server.isAnnotationPresent(Deprecated.class)));
      assertThat(bukkit.getReturnType(), is((Object) server.getReturnType()));
      assertThat(bukkit.getGenericReturnType(), is(server.getGenericReturnType()));
      assertThat(bukkit.getGenericParameterTypes(), is(server.getGenericParameterTypes()));
      assertThat(bukkit.getGenericExceptionTypes(), is(server.getGenericExceptionTypes()));
  }
\end{lstlisting}

\vspace*{-1em}
\section*{Question 2: Fuzzing (10 points)}
% I provide code and a test case generator. Test cases all get filtered out at a bottleneck in the code. Provide a test case generator that explores more of the code. Explain the phenomenon.
\begin{lstlisting}
  float computeAngle(int x, int y, int z) {
    if (x * x + y * y != z * z) {
      throw new IllegalArgumentException("bad triangle");
    }
    return Math.atan2(y, x);
  }
\end{lstlisting}
\begin{itemize}[noitemsep]
\item (5 points) Write a Java function {\tt naiveComputeAngleTest()} that generates a completely-pseudorandom input triple $(x, y, z)$ for this method and calls it. Would {\tt naiveComputeAngleTest()} give you good insight
  into what {\tt computeAngle()} does? Explain your answer.
\item (5 points) Write a Java function {\tt smartComputeAngleTest()} that randomly generates an input that never triggers an {\tt IllegalArgumentException}. You may use {\tt Math.sqrt()}, which returns a double.
\end{itemize}
(To get a pseudorandom number: {\tt Random r = new Random(); i = r.nextInt(); })

\newpage
\section*{Question 3: Short-circuit evaluation (15 points)}
Here is a simplified version of code from Assignment 1.
\begin{lstlisting}
  String buildCommand(String formatString) {
    // returns the index at which '$' appears in formatString or -1 if not present
    int index = formatString.indexOf("$");
    while (index != -1) {
      if (index > 0 && formatString.charAt(index - 1) == '!') {
        // removes the '$' at index from formatString
        formatString = formatString.substring(0, index - 1) + formatString.substring(index);
        index = formatString.indexOf("$", index);
        continue;
      } else {
        ;
      }
      index = formatString.indexOf("$", index + 1);
    }
  }
\end{lstlisting}
\begin{itemize}[noitemsep]
\item (5 points) Draw a control-flow graph for this method. Nodes as basic blocks, labelled with line
  numbers. Explicitly write boolean conditions. (Be careful with the short-circuit evaluation.) I had 7 nodes.
\item (10 points) Test suite \verb+"$"+, \verb+"!$"+ achieves 100\%
  statement coverage but jacoco says ``1 branches out of 4 missed'' at
  the {\tt if} statement. Describe the missing branch and explain why
  it is missing (for 5 points) and write down a test case that achieves 100\%
  branch coverage (another 5 points). (Warning: because I removed code, this behaves
  slightly differently than on the assignment).
\end{itemize}

\newpage
\section*{Question 4: Statement and Branch Coverage (20 points)}
\begin{lstlisting}
public static List<String> wrap(String input, int line_length) {
  List<String> rv = new ArrayList<String>();
  int last_break = -1, last_space = 0;

  for (int i = 0;
       i < input.length();
       i++) {
    if (input.charAt(i) == ' ') {
      last_space = i;
    }

    if (i - last_break > line_length) {
      rv.add(input.substring(last_break + 1, last_space));
      last_break = i;
    }
  }
  if (last_space >= last_break + 1) {
    rv.add(input.substring(last_break + 1, last_space));
  }
  return rv;
}
\end{lstlisting}

\vspace*{1em} \noindent
(a) (5 points) Draw a minimal-node (9) control-flow graph for this method, with
nodes as basic blocks. Label the nodes with the line numbers on the left.

\vspace*{1em} \noindent
(b) (10 points) Consider \verb+input = "one three two ", line_length = 9+.
Argue that this input achieves statement coverage. You may use the fact that the output is:
\begin{verbatim}
$ java Justify 9 "one three two "
one three
two
\end{verbatim}

\vspace*{1em} \noindent
(c) (5 points) Does my input also achieve branch coverage? Why or why not? (If so, say why; if not,
say specifically which branch is not covered).

\newpage
\section*{Question 5: Understanding Mutation (25 points)}
(a) (10 points) Write down a non-trivial mutant of {\tt wrap()} that
is killed by {\bf my} test case (from (1b)). (Write the line number that you are changing
and what you want it to say, e.g.:)

\verb+Line 5: for (int i = -1;+

\noindent
Explain why my test case
kills the mutant (show outputs). Also show why the mutant is non-trivial; that is,
find a non-empty input on which the mutant and the original do not differ.
% last_break = 0 should work if you give it a one-line input for non-triviality

\vspace*{1em} \noindent
(b) (5 points) Write down a test case for {\tt wrap()} (from Question
4) that reveals a bug in the original program. Include actual and expected output.
(Contract: the concatenation of the strings
returned from {\tt wrap()} must equal {\tt input}.)
You do not have to identify or fix the bug.
  Clearly, this
test case does not improve statement coverage beyond the input from
(4b).

\vspace*{1em} \noindent
(c) (10 points) Write down a different non-trivial mutant of {\tt
  wrap()} that is killed by {\bf your} test case (from part b) and explain why your test
case kills the mutant (show outputs).  Again explain why the mutant is non-trivial;
that is, find a non-trivial input on which the mutant and the original
do not differ.

Observe that you've used mutation to improve your test suite from what
it was in (4b).  You generated a mutant, and the test case from (4b)
killed the mutant from (4c). On the other hand, both statement and branch
coverage don't get you anything more.

%[or, provided bug not killable by mutation]

%does your test case improve stmt coverage? branch coverage?

%\section*{Question 6: Finite State Machines (5 points)}
%read a document describing a system; create an FSM and test cases for that system

\end{document}


\pgfkeys{
	/pgfplots/Interval/.style={
	axis x line=middle,
	axis y line=none,
	every axis x label/.style={
		at={(ticklabel* cs:1.05)},
		anchor=west,
	},
	axis line style={stealth-stealth, thick},
	label style={font=\large},
	tick label style={font=\small},
	samples=200,
	xmin=-5, xmax=5,
	ymin=0, ymax=5,
	domain=-5:5,
	y=0.5cm,
	restrict y to domain=0:4,
	axis lines=left,
	enlarge x limits=upper,
	scatter/classes={o={mark=*,fill=white}},
	scatter,
	scatter src=explicit symbolic,
	every axis plot post/.style={mark=*,thick},
}}

\chapter{Introduction}\label{chapter:intro}
In this chapter we introduce key concepts that will be used in later chapters. For this reason, unlike other chapters it contains many statements, sometimes given without thorough explanations or reasoning. While all of these statements are grounded in deep ideas and can be formulated in a rigorous manner, it is advised to first get an intuitive understanding of the ideas before diving into their more formal construction.

\vspace{2em}
\begin{note}{In case you are already familiar with the topics}{}
	It is recommended for readers who are familiar with the topics to at least gloss over this chapter and make sure they know and understand all the concepts presented here.
\end{note}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%% SERPENT  INTERFACE  %%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\subsection{SERPENT Interface}
\label{subsec:serpentInterface}
The Serpent interface is meant to run multiple user-defined SERPENT simulations
while storing the following values:
\begin{itemize}
\item Input composition
\item Depletion time
\item Output composition
\item Beginning Of Cycle / End Of Cycle Keff
\end{itemize}

It allows users to run SERPENT by varying a value
(e.g. depletion time, input composition) from a template input file.
For example, a user can run a \texttt{MultiRun} where the depletion
time of a fixed input composition is varied, to see the effect of
depletion time on the output composition and End Of Cycle Keff.

There are some limitations for this interface:
\begin{itemize}
\item Only the parameters mentioned above will be stored in the output csv file
\item You cannot run multiple depletion steps
\end{itemize}

Due to the large number of isotopes that might be tracked,
a utility script is provided in
$RAVEN\_HOME/framework/CodeInterfaces/SERPENT/utilityForCreatingVariables$
to create the variable names that can be used in a RAVEN input file.

The user can edit the \texttt{isoFile} so that it
matches the exact isotope nomenclature used in the SERPENT simulations for the isotopes
to be in the output csv file. To do so:

\begin{enumerate}
\item edit \texttt{isoFile} to match isotope nomenclature in SERPENT
\item run \texttt{python generateCustomVariable.py}
\end{enumerate}

This will automatically generate the feature and target space XML files
used in the RAVEN input file.

\subsubsection{Models}
In order to run the code, make sure you have a valid SERPENT input file.

In the RAVEN input file, your \xmlNode{Models} node should look like:
\begin{lstlisting}[style=XML]
<Models>
    <Code name="SERPENT" subType="Serpent">
      <!-- path to your serpent executable -->
      <executable>/my/path/to/serpent/sss2</executable>
      <clargs arg="" extension=".serpent" type="input"/>
      <clargs arg="--noplot" type="postpend"/>
      <traceCutOff>1e-6<traceCutOff/>
      <isotope_list>mylist.csv<isotope_list/>
      <!-- or
      <isotope_list>
        1001,290750,34078,38089,411090,451121,
        481191,501281,531390,571450,611570,671661,882280
      <isotope_list/>
      -->
    </Code>
</Models>
\end{lstlisting}
where the \xmlNode{executable} and \xmlNode{clargs} should me modified
to create the appropriate run command for SERPENT. In this example, the command
to run raven is:
\begin{lstlisting}[language=bash]
/my/path/to/serpent/sss2 [inputFile] --noplot
\end{lstlisting}
where the \texttt{inputFile} is defined in the \xmlNode{Files} node as:
\begin{lstlisting}[style=XML]
<Files>
    <Input name="originalInput" type="">serpent_input.serpent</Input>
</Files>
\end{lstlisting}

Two additional XML nodes can be added in the bloc:

\begin{itemize}
   \item \xmlNode{traceCutOff}, \xmlDesc{float, optional parameter},  the trace cut off density.
   \item \xmlNode{isotope\_list}, \xmlDesc{string or comma separated list, required parameter}, This node contains the list
   of isotopes to track. If a ``csv'' is provided, the list is read from such file, otherwise the isotopes are read from the node
   directly.
\end{itemize}

\subsubsection{Files}
The only input file needed is a complete SERPENT input file,
which means that it should either be self sufficient, or includes
the necessary files (e.g. geometry, material definition files).
The input file extension will depend on the the extension definition
in the \xmlNode{Models} node.

\subsubsection{Samplers / Optimizers}
In the \xmlNode{Samplers} block the user can define the variables
to be sampled.
\textbf{Example:} If the user wants to vary depletion time from
10 to 100 days, the SERPENT input file \texttt{dep} definition is as such:
\begin{lstlisting}
dep daystep
$RAVEN-deptime$
\end{lstlisting}

Then in the RAVEN input file, the \xmlNode{Samplers} block would be:
\begin{lstlisting}[style=XML]
  <Samplers>
    <Grid name="myGrid">
      <variable name="deptime">
        <distribution>timedist</distribution>
        <!-- equally spaced steps with lower and upper bound -->
        <grid construction="equal" steps="100" type="CDF">0.1 1</grid>
      </variable>
    </Grid>
  </Samplers>
\end{lstlisting}
where the distributiong \texttt{timedist} is defined in the \xmlNode{Distributions}:
\begin{lstlisting}[style=XML]
  <Distributions>
    <!-- uniform distribution from 0.1 to 1 -->
    <Uniform name="timedist">
      <lowerBound>0.0</lowerBound>
      <upperBound>100</upperBound>
    </Uniform>
</Distributions>
\end{lstlisting}

Then this run would be defined in the \xmlNode{Steps} block as \xmlNode{MultiRun}:
\begin{lstlisting}[style=XML]
<MultiRun name="runGrid">
      <!-- runGrid runs serpent by the number of steps with sampled variable -->
      <Input   class="Files"       type=""          >originalInput</Input>
      <Model   class="Models"      type="Code"      >SERPENT</Model>
      <Sampler class="Samplers"    type="Grid"      >myGrid</Sampler>
      <Output  class="DataObjects" type="PointSet"  >outPointSet</Output>
</MultiRun>
\end{lstlisting}

\subsubsection{Output Files Conversion}
A single SERPENT run creates at least three output files,
\texttt{[input]\_res.m, [input].out, [input]\_dep.m}.
Since the interface is
focused on acquiring the depleted composition, the \texttt{[input].bumat[n]}
file is used as well. Examples of the SERPENT output files are replicated below.

\begin{lstlisting}[language={}]
% bumat file
% .bumat0 is initial, .bumat1 is depleted
mat  fuel  7.98978775163891E-02 vol 1.95057E+07
            % isotope    % atomic density
            3006.09c  1.27142536007818E-06
            3007.09c  2.27080541933364E-02
           90232.09c  3.79539634267135E-03
           92233.09c  6.32566047430223E-05
\end{lstlisting}

\begin{lstlisting}[language={}]
% _res.m file
% The file contains all results by the code, including Keff value
% Only the section with criticality eigenvalues are used.

% Criticality eigenvalues:
% [mean standard dev]
ANA_KEFF  (idx, [1:   6]) = [  9.69430E-01 0.00074  1.07409E-01 0.00074  3.01736E-04 0.01757 ];
IMP_KEFF  (idx, [1:   2]) = [  9.69535E-01 0.00030 ];
COL_KEFF  (idx, [1:   2]) = [  9.69943E-01 0.00070 ];
\end{lstlisting}

The interface parses through \texttt{[input]\_res.m} file
to obtain the Beginning Of Cycle and End Of Cycle Keffs, and the
\texttt{[input].bumat0} and \texttt{[input].bumat1} file to obtain the
input / output compositions. In the output csv file, the input compositions
are prepended with the letter `f', and the output compositions with the letter `d'
(e.g. f92235, d94239), for separation.

An example is given below where only two isotopes, U-235 and Pu-241 are tracked.
The values under the isotopes are in atomic density.

\begin{table}[h]
  \centering
  \resizebox{\textwidth}{!}{
    \begin{tabular}{|l|l|l|l|l|l|l|}
      \hline eocKeff
      f92235 & f94241 & deptime & eocKeff & bocKeff & d92235 & d94241 \\
      \hline
      6.32e-05 &  0.00 & 1.0 & 0.9694 &  9.6065 & 3.79e-03 & 7.07e-41 \\
      \hline
      6.32e-05 &  0.00 & 10.0 & 0.9694 &  9.536 & 6.32e-05 & 4.50e-37 \\
      \hline
    \end{tabular}
    }
    \caption{Example csv file generated by RAVEN running SERPENT}
    \label{tab:ser-rav}
\end {table}


\documentclass[12pt]{article}
\usepackage{graphicx}
\usepackage{enumerate}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[mathscr]{euscript}
\usepackage{hyperref}
\usepackage{bbm}

\hypersetup{
    colorlinks=true,
    urlcolor=blue
}

\setlength{\oddsidemargin}{.1in}
\setlength{\textwidth}{6.3in}
\setlength{\textheight}{8.9in}
\setlength{\topmargin}{-.5in}

\title{Solving the inverted pendulum task via policy iteration}
\date{}

\begin{document}

\maketitle

\section{Reflections so far}

Last chapter's solution to the inverted pendulum task was unsatisfactory. While the solution worked reasonably well in certain cases---for instance, it produced somewhat intelligent-looking pendulum-balancing behavior when the pendulum was nearly upright with low angular velocity---it certainly did not maintain balance generally, and could not recover once fallen over. The solution performed poorly due to two stiff limitations on our setting of the MDP: the state space was very coarse-grained, and our estimates of the transition probabilities were only a very rough approximation of ``real experience''.

In this chapter we work out an alternative method for solving the MDP which does not require a direct numerical solution. This new method---\textit{policy iteration}---is generally less expensive than directly solving the Bellman equations. This will ease the first of the two aforementioned limitations, allowing us to set the MDP in a more fine-grained state space. In the next chapter we'll take on the second limitation, working out a method to estimate transition probabilities by sampling from real experience.

\section{Policy iteration}

At one point in the last chapter we stopped and noted the following. We can readily characterize a value function with respect to any given policy, and we can easily find an optimal policy with respect to any given value function:

\begin{align}
\pi^*(s) &= \underset{a}{\arg\max} \, \sum_{s^\prime \in \mathscr{S}} P_a(s, s^\prime) V(s^\prime) \\[5pt]
V(s) &= \sum_{s^\prime \in \mathscr{S}} P_{\pi(s)}(s, s^\prime) \Big(R_{\pi(s)}(s, s^\prime) + \gamma V(s^\prime)\Big).
\end{align}

In the end, we wrote down a set of Bellman equations which could be solved directly for the optimal policy. Recall, however, that we had to solve a set of $|\mathscr{S}|$ nonlinear recurrence relations in $|\mathscr{S}|$ variables, each one requiring a maximum over $|\mathscr{A}|$ expressions. This was akin to an exhaustive search over all possible actions that could be taken in all possible states in order to transition into all possible states.

Instead of solving for the optimal policy and optimal value function all at once, we can imagine a step-wise back-and-forth solution which goes something like this:

\begin{enumerate}
\item{Select a random policy.}
\item{Compute the true value function under this policy.}
\item{With this true value function, we can see a better policy than the original one. Select that policy instead.}
\item{Compute the true value function under this new policy.}
\item{Using this new true value function, we can see an even better policy. So we choose that one instead... and so forth.}
\item{We repeat this process, back and forth, until we find that we no longer need to change our policy. At this point we are guaranteed to have an optimal policy.}
\end{enumerate}

This process is called \textit{policy iteration}. Sutton \& Barto (2017) offer an insightful distillation of the concept:

\begin{quote}
[Policy iteration] is the general idea of two interacting processes revolving around an approximate policy and an approximate value function. One process takes the policy as given and perform some form of policy evaluation, changing the value function to be more like the true value function for the policy. The other process takes the value function as given and performs some form of policy improvement, changing the policy to make it better, assuming that the value function is its value function. Although each process changes the basis for the other, overall they work together to find a joint solution: a policy and value function that are unchanged by either process and, consequently, are optimal.
\end{quote}

To implement this, we just need to work out the details for each of the two steps:
\begin{enumerate}[(i)]
\item{finding the value function for a policy (policy evaluation)}
\item{finding the optimal policy for a value function (policy improvement)}.
\end{enumerate}

We've already examined each of these steps in the past. Here we'll write out and explore their equations a refresher, starting with policy improvement.

Let's say that I'm handed a value function from on high. For the time being it doesn't matter under which policy is was computed, all that matters is that I have some function which accepts a state as an argument and returns the value of that state. Choosing an optimal policy is straightforward: we simply choose, at each state, the action which maximizes the expected value of the state which will follow.

\begin{equation}
\pi^*(s) = \underset{a}{\arg\max} \, \sum_{s^\prime \in \mathscr{S}} P_a(s, s^\prime) V(s^\prime).
\end{equation}

In the last chapter we also derived the equation for the value function given a particular policy. It's the expected reward that results immediately from acting on our policy, plus the discounted expected value of the state which will follow:

\begin{equation}
\label{eq:value} V(s) = \sum_{s^\prime \in \mathscr{S}} P_{\pi(s)}(s, s^\prime) \Big(R_{\pi(s)}(s, s^\prime) + \gamma V(s^\prime)\Big).
\end{equation}

Of the two steps, this is the one which requires more computational effort. Finding $V(s)$ requires solving a set of $|\mathscr{S}|$ linear equations in $|\mathscr{S}|$ unknowns. Roughly, we have two options for solving this system: (i) directly, using methods from linear algebra, and (ii) via iterative numerical methods.

\section{Computing the value function}

Here we'll just consider the linear algebraic solution. Note that the function $V_\pi(s)$ can be represented by a lookup table holding the value for each individual state. If we have $k$ states, this table is a vector of $k$ entries where the $i^{th}$ entry is the value of the $i^{th}$ state in the set of all states:

\begin{equation}
\mathbf{v} \, | \, v_i = V(s_i) \, \mbox{for} \, i = \left\{1, ..., k\right\} \, \mbox{where} \, |\mathscr{S}| = \left\{s_1, ..., s_k\right\}.
\end{equation}

We'll denote the policy as a lookup table as well, a vector of $k$ elements where the $i^{th}$ element is an index in the range $\left\{1, ..., m\right\}$ for the action to be taken in state $s_i$, with $m$ being the total number of actions available (that is, $\mathscr{A} = \left\{a_1, ..., a_m\right\}$):

\begin{equation}
\mathbf{\pi} \, | \, \pi_i = \pi(s_i).
\end{equation}

The transition probabilities can be represented by another lookup table, this time a $k \times k$ matrix where the entry $i,j$ is the probability of transitioning from state $s_i$ to $s_j$ due to action $\pi_i$:

\begin{equation}
P \, | \, P_{i,j} = P_{\pi_i}(s = s_i, s^\prime = s_j).
\end{equation}

Like the transition probabilities, the reward function is a lookup table in the form of a matrix---a $k \times k$ matrix where the entry $i,j$ is the immediate scalar reward received from transitioning from state $s_i$ to $s_j$ due to action $\pi_i$:

\begin{equation}
R \, | \, R_{i,j} = R_{\pi_i}(s = s_i, s^\prime = s_j).
\end{equation}

Now we have the machinery in place to re-write equation (\ref{eq:value}) with our vectors and matrices. For the state $s_i$, the scalar value $v_i$ is given by

\begin{align}
v_i &= \sum_{j = 1}^k P_{i,j}(R_{i,j} + \gamma v_j) \\[5pt]
&= \sum_{j = 1}^k P_{i,j} R_{i,j} + \gamma \sum_{j = 1}^k P_{i,j} v_j.
\end{align}

Let $\mathbf{p}_i$ be a vector representing the $i^{th}$ row of $P$ and $\mathbf{r}_i$ be a vector representing the $i^{th}$ column of $R^T$ (or, equivalently, the $i^{th}$ row of $R$). We can collapse the sums to dot products and write the above equation as

\begin{equation}
v_i = \mathbf{p}_i \cdot \mathbf{r}_i + \gamma \mathbf{p}_i \cdot \mathbf{v}.
\end{equation}

This can be expressed even more compactly by the matrix multiplication

\begin{equation}
\mathbf{v} = P R^T + \gamma P \mathbf{v}.
\end{equation}

Subtracting $\mathbf{v}$ from the right hand side gives

\begin{equation}
0 = (\gamma P - 1)\mathbf{v} + P R^T,
\end{equation}

and this is a nonhomogeneous linear equation of the form

\begin{equation}
A \mathbf{v} + \beta = 0 \, \mbox{where} \, A = \gamma P - 1 \, \mbox{and} \, \beta = P R^T
\end{equation}

which is satisfied when

\begin{align}
\mathbf{v} &= -A^{-1} \beta \\[5pt]
&= -(\gamma P - 1)^{-1} P R^T \\[5pt]
&= (1 - \gamma P)^{-1} P R^T.
\end{align}

This is our algebraic solution for $V(s)$.

---------------------------------------------

TO DO:

-conceptual re-casting of the explanation, severe revision

-consistency of language, decide which terms to use, and then define and use those only

-explain iterative policy evaluation?

-philosophical discussion of bootstrapping nature of reinforcement learning

-fix notation in matrix math!---should not be $P R^T$ but a vector produced by dotting each row of P with each row of R

\end{document}


\documentclass[a4paper,11pt]{article}
\pdfoutput=1 % if your are submitting a pdflatex (i.e. if you have
             % images in pdf, png or jpg format)

\usepackage{jheppub} % for details on the use of the package, please
                     % see the JHEP-author-manual

\usepackage[T1]{fontenc} % if needed

\title{\boldmath Notes: Spherically symmetric black hole dynamics in $4\partial ST$ gravity}

%% %simple case: 2 authors, same institution
%% \author{A. Uthor}
%% \author{and A. Nother Author}
%% \affiliation{Institution,\\Address, Country}

% more complex case: 4 authors, 3 institutions, 2 footnotes
\author[a,1]{Justin L. Ripley}

% The "\note" macro will give a warning: "Ignoring empty anchor..."
% you can safely ignore it.

\affiliation[a]{
   DAMTP, Centre for Mathematical Sciences, University of Cambridge,
   \\ Wilberforce Road, Cambridge CB3 0WA, UK.
}

% e-mail addresses: one for each author, in the same order as the authors
\emailAdd{lloydripley@gmail.com}
%\emailAdd{weast@perimeterinstitute.ca}
%\emailAdd{Thomas.Sotiriou@nottingham.ac.uk}

\abstract{
   Notes on the equations of motion and numerical implementation.
   If you end up using this code, while some implementation details
   have changed since original publication please consider
   citing \cite{Ripley:2020vpk}.
   }

\begin{document}
\maketitle
\flushbottom

\section{Introduction}
\label{sec:intro}

We set $G=c=1$, our metric signature is $-+++$,
we use lower case Latin indices to index spacetime dimensions,
the Riemann tensor is
$R^a{}_{mbn}=\partial_{b}\Gamma^{a}_{mn}-\cdots$.

%\begin{figure}[tbp]
%\centering % \begin{center}/\end{center} takes some additional vertical space
%\includegraphics[width=.45\textwidth,trim=0 380 0 200,clip]{img1.pdf}
%\hfill
%\includegraphics[width=.45\textwidth,origin=c,angle=180]{img2.pdf}
%% "\includegraphics" is very powerful; the graphicx package is already loaded
%\caption{\label{fig:i} Always give a caption.}
%\end{figure}

%=============================================================================
\section{Equations of motion}
   We consider the theory (``$4\partial ST$ gravity'', e.g. \cite{Kovacs:2020ywu})
\begin{align}
   S
   =
   \frac{1}{8\pi}\int d^4x\sqrt{-g}\left(
      \frac{1}{2}R
   +  X
   -  V(\phi)
   +  \alpha(\phi)X^2
   +  \beta(\phi)\mathcal{G}
   \right)
   ,
\end{align}
   where
\begin{subequations}
\begin{align}
   X
   \equiv&
-  \frac{1}{2}\left(\nabla\phi\right)^2
   ,\\
   \mathcal{G}
   \equiv&
   \frac{1}{4}\delta^{abcd}_{efgh}
   R^{ef}{}_{ab}R^{gh}{}_{cd}
   ,\\
   \delta^{abcd}_{efgh}
   \equiv&
   4!\delta^a_{[e}\delta^b_f\delta^c_g\delta^d_{h]}
   .
\end{align}
\end{subequations}
   Varying the action with respect to the scalar field and metric field
gives us the equations of motion:
\begin{align}
\label{eq:eom_edgb_scalar}
   E^{(\phi)}
   &\equiv
      \Box\phi
   -  V^{\prime}\left(\phi\right)
   \nonumber\\&
   +  2\alpha\left(\phi\right)X \Box\phi
   -  2\alpha\left(\phi\right)\nabla^a\phi\nabla^b\phi\nabla_a\nabla_b\phi
   \nonumber\\&
   -  3\alpha^{\prime}\left(\phi\right)X^2
   +  \beta^{\prime}\left(\phi\right)\mathcal{G}
   =
   0
   ,\\
\label{eq:eom_edgb_tensor}
   E^{(g)}_{ab}
   &\equiv
   R_{ab}
-  \frac{1}{2}g_{ab}R
   \nonumber\\&
-  \nabla_a\phi\nabla_b\phi
+  \left(-X+V\left(\phi\right)\right)g_{ab}
   \nonumber\\&
-  2\alpha\left(\phi\right)X\nabla_a\phi\nabla_b\phi
-  \alpha\left(\phi\right)X^2g_{ab}
   \nonumber\\&
+  2\delta^{efcd}_{ijg(a}g_{b)d}R^{ij}{}_{ef}
   \nabla^g\nabla_c\beta\left(\phi\right)
   =
   0
   .
\end{align}
%=============================================================================
\section{Numerical implementation}
%=============================================================================
\subsection{Coordinates}
   Our procedure for numerically evolving this system in spherical symmetry
will largely follow the analysis of \cite{Ripley:2020vpk}.
We numerically evolve this system in Painlev\'{e}-Gullstrand (PG)-like
coordinates:
\begin{align}
   ds^2
   =
-  N(t,r)^2dt^2
+  \left(dr+N(t,r)S(t,r)dt\right)^2
+  r^2\left(d\vartheta^2+\mathrm{sin}^2\vartheta d\varphi^2\right)
   ,
\end{align}
   which are so-named as in the static limit black hole solutions are given
by the Painlev\'{e}-Gullstand coordinate representation of the Schwarzschild
black hole: $N=1$, $S=\sqrt{2m/r}$.

   We define the variables:
\begin{subequations}
\begin{align}
   Q
   \equiv&
   \partial_t\phi
   ,\\
   P
   \equiv&
   \frac{1}{N}\partial_t\phi-S Q
   ,
\end{align}
\end{subequations}
   and obtain the following system of evolution equations for
$\phi$, $Q$, and $P$:
\begin{subequations}
\begin{align}
   E_{(\phi)}
   \equiv&
   \partial_t\phi
-  N\left(P+S Q\right)
   = 0
   ,\\
   E_{(Q)}
   \equiv&
   \partial_tQ
-  \partial_r\left(N\left[P+S Q\right]\right)
   = 0
   ,\\
   E_{(P)}
   \equiv&
   \mathcal{A}_{(P)}\partial_tP
+  \mathcal{F}_{(P)}
   = 0
   ,
\end{align}
\end{subequations}
   where $\mathcal{A}_{(P)}$ and $\mathcal{F}_{(P)}$
are functions of $P,Q,\phi,N,S$, and their radial derivatives.
We can solve for the metric field variables using the
Hamiltonian ($\mathcal{H}=0$) and momentum $\mathcal{M}_r=0$)
constraint equations.
Using the unit timelike vector to our $t=const.$ hypersurfaces:
$n_a=(-N,0,0,0)$ these are defined to be
\begin{align}
\label{eq:metric_field_odes}
   \mathcal{H}
   \equiv
   E^{(g)}_{ab}n^an^b
   \propto&
   \left(
      1
   -  8\beta^{\prime}\frac{Q}{r}
   -  12\beta^{\prime}\frac{P S}{r}
   \right)
   \partial_rS
+  \left(
      S
   -  9\beta^{\prime}\frac{QS}{r}
   -  12\beta^{\prime}\frac{PS^2}{r}
   \right)
   \frac{\partial_rN}{N}
   \nonumber\\&
-  4\beta^{\prime}\frac{S}{r}\partial_rQ
-  4\beta^{\prime\prime}\frac{Q^2S}{r}
+  \frac{S}{2r}
-  \frac{1}{2}\frac{r\rho}{S}
   ,\\
   \mathcal{M}_r
   \equiv
   E^{(g)}_{ar}n^a
   \propto&
   \left(
      1
   -  8\beta^{\prime}\frac{Q}{r}
   -  8\beta^{\prime}\frac{PS}{r}
   +  4\beta^{\prime}\frac{QS^2}{r}
   \right)
   \frac{\partial_rN}{N}
+  4\beta^{\prime}\frac{QS}{r}\partial_rS
+  4\beta^{\prime}\frac{S}{r}\partial_rP
   \nonumber\\&
+  4\beta^{\prime\prime}\frac{P Q S}{r}
-  \frac{1}{2}\frac{r j_r}{S}
   ,
\end{align}
   where $r$ is the radial index, and
\begin{subequations}
\begin{align}
   \rho
   \equiv&
   n^an^bT_{ab}
   ,\\
   j_r
   \equiv&
-  n^aT_{ar}
   ,\\
   T_{ab}
   \equiv&
   \left(
      1+ 2 \alpha X
   \right)
   \nabla_a\phi\nabla_b\phi
+  g_{ab}
   \left(
      X
   -  V
   +  \alpha X^2
   \right)
   .
\end{align}
\end{subequations}
   For our initial data, we freely specify $\phi$ and $P$.
We obtain $Q=\partial_r\phi$, and solve for the metric fields using
the Hamiltonian and momentum constraint equations.
There is a residual gauge symmetry which allows us
to rescale $N$ by a constant value at each time step;
we use this freedom to rescale $N$ such
that $\lim_{r\to\infty}N=1$.
A trapped surface is signaled by $S<1$;
thus to begin with black hole initial data we set $S<1$ at some
excision point.

   As independent residual checks on our solutions, we plug our
solution into the $rr$ component of the tensor equations, $E^{(g)}_{rr}=0$,
and consider $Q-\partial_r\phi=0$, both of which should converge
to zero with higher resolution.

   We compactify the radial coordinate in the code:
\begin{align}
   x
   \equiv
   \frac{r}{1+r/L}
   ,
\end{align}
   where $L$ is the compactification radius.
%=============================================================================
\subsection{Form of scalar field potentials}
   We consider potentials of the form
\begin{subequations}
\begin{align}
   V\left(\phi\right)
   =&
   V_1\phi
+  \frac{1}{2}V_2\phi^2
+  \frac{1}{6}V_3\phi^3
+  \frac{1}{24}V_4\phi^4
   ,\\
   \alpha\left(\phi\right)
   =&
   \alpha_0
+  \alpha_1\phi
+  \frac{1}{2}\alpha_2\phi^2
+  \frac{1}{6}\alpha_3\phi^3
+  \frac{1}{24}\alpha_4\phi^4
   ,\\
   \beta\left(\phi\right)
   =&
   \beta_1\phi
+  \frac{1}{2}\beta_2\phi^2
+  \frac{1}{6}\beta_3\phi^3
+  \frac{1}{24}\beta_4\phi^4
+  \frac{1}{6}\beta_{e}\left(1-e^{-3\phi^2}\right)
   .
\end{align}
\end{subequations}
   Where all the subscripted quantities, e.g. $\alpha_2$, are constants
determined by the user in the {\bf setup\_run.py} file.
We do not put in a $V_0$ (a cosmological constant) as generically
spacetimes with cosmological constants are not aysmptotically flat,
and we do not put in a $\beta_0$ term as the Gauss-Bonnet scalar
does not constribute to the equations of motion in that case.
%==============================================================================
%\acknowledgments

%This is the most common positions for acknowledgments. A macro is
%available to maintain the same layout and spelling of the heading.

%\paragraph{Note added.} This is also a good position for notes added
%after the paper has been written.

\bibliographystyle{JHEP}
\bibliography{spherical}
\end{document}