% Copyright 2018-2021 Melvin Eloy Irizarry-Gelpí
\setcounter{chapter}{4}
\chapter{Circuits with Capacitors and Inductors}
%
In this experiment you will learn about circuits with capacitors and inductors.
%
\section{Preliminary}
%
A given component in an electric circuit can have many physical properties. Among them are resistance, capacitance, and inductance.
%
\subsection{Resistance and Resistors}
%
By now, electrical \textbf{resistance} should be familiar. The \textbf{SI unit} for electrical resistance is the \textbf{ohm}:
\begin{equation}
	1 \ \text{ohm} = 1 \ \text{V/A}
\end{equation}
Here, V is volt (voltage) and A is ampere (current). A component in a circuit with a fixed amount of resistance is called a \textbf{resistor}. The \textbf{mathematical symbol} for resistance is $R$.
%
\subsection{Capacitance and Capacitors}
%
Another important property is \textbf{capacitance}. The \textbf{SI unit} for capacitance is the \textbf{farad}:
\begin{equation}
	1 \ \text{farad} = 1 \ \text{F} = 1 \ \text{C/V}
\end{equation}
Here, C is coulomb (electric charge) and V is volt (voltage). In some ways, capacitance measures the amount of electric charge needed to sustain an electric potential difference (i.e. a voltage). The \textbf{mathematical symbol} for capacitance is $C$.

A component in a circuit with a fixed amount of capacitance is called a \textbf{capacitor}. For practical purposes, you can think of a capacitor as two parallel plates of conducting material where equal but opposite amounts of electric charge can accumulate.
%
\subsection{Inductance and Inductors}
%
The last property is \textbf{inductance}, which is like a magnetic cousin of capacitance. The \textbf{SI unit} for inductance is the \textbf{henry}:
\begin{equation}
	1 \ \text{henry} = 1 \ \text{H} = 1 \ \text{T {\textperiodcentered} m\textsuperscript{2}/A}
\end{equation}
Here, T is tesla (magnetic field), m\textsuperscript{2} is square meter (area), and A is ampere (current). Recall that the tesla unit is equivalent to
\begin{equation}
    1 \ \text{T} = 1 \ \text{V {\textperiodcentered} s/m\textsuperscript{2}}
\end{equation}
Thus, the henry unit is equivalent to:
\begin{equation}
    1 \ \text{H} = 1 \ \text{V {\textperiodcentered} s/A} = 1 \ \text{ohm {\textperiodcentered} s}
\end{equation}
In some ways, inductance measures the amount of voltage that arises per unit rate of change of electric current with time. The \textbf{mathematical symbol} for inductance is $L$.

A component in a circuit with a fixed amount of inductance is called an \textbf{inductor}. You can think of an inductor as a solenoid coil with a given amount of loops, with each loop enclosing some amount of area.
%
\subsection{Exponential Decay Function}
%
Before discussing the behavior of current and voltage in circuits with capacitors and inductors, it will be good to review the exponential decay function:
\begin{equation}
    \exp(-t) = e^{-t}
\end{equation}
Here, $e$ is the \textbf{natural base}:
\begin{equation}
    e = 2.71828...
\end{equation}
When $t = 0$, the exponential decay function gives
\begin{equation}
    \exp(0) = 1
\end{equation}
For large values of $t$, the exponential decay function approaches 0:
\begin{equation}
    \exp(-\infty) = 0
\end{equation}
In between $t = 0$ and $t \rightarrow \infty$ you have smaller and smaller values approaching zero.

The exponential decay function is an example of a function that is always positive, and always \textbf{decreasing} towards zero:
\begin{align}
    f(t) = \exp(-t) && 0 < f(t) \leq 1 && 0 \leq t < \infty
\end{align}
Multiplying the exponential decay function by a negative sign produces a function that is always negative, and always \textbf{increasing} towards zero:
\begin{align}
    g(t) = -\exp(-t) && -1 \leq g(t) < 0 && 0 \leq t < \infty
\end{align}
Another important combination is shifting vertically by 1, which gives a function that is always positive, and always \textbf{increasing} towards one:
\begin{align}
    h(t) = 1 - \exp(-t) && 0 \leq h(t) < 1 && 0 \leq t < \infty
\end{align}
Figures \ref{figure.05.f}, \ref{figure.05.g}, and \ref{figure.05.h} provide charts for these three functions.
%
\subsection{Resistor and Capacitor in Series}
%
A circuit with a resistor, a capacitor, and a direct-current (DC) EMF source is called an \textbf{RC circuit}. In the simplest RC circuit, the resistor and capacitor are connected in series to the DC EMF source via a particular switch.
%
\subsubsection{Charging the Capacitor}
%
When the switch is on, and the circuit is complete, the DC EMF source pushes charges out into the circuit in the form of a current. This current causes positive electric charges to accumulate on one of the terminals of the capacitor, and negative electric charges on the other terminal of the capacitor. But the amount of electric charge $Q$ on the capacitor does not increase indefinitely: It settles on a maximum value $Q_{\infty}$. The particular manner in which the amount of \textbf{electric charge} on the capacitor increases with time is an example of an \textbf{exponential} increase:
\begin{equation}
    Q(t) = Q_{\infty} \left[ 1 - \exp\left(-\frac{t}{\tau_{C}}\right) \right]
    \label{eq.05.RC.q.charging}
\end{equation}
Here $Q_{\infty}$ is the amount of charge accumulated on the capacitor after an infinite amount of time, and $t$ corresponds to the amount of time after the switch has been opened (the switch is opened at $t = 0$). The amount of \textbf{current} corresponds to the rate of change of the electric charge with time:
\begin{equation}
    I(t) = I_{0} \exp\left(-\frac{t}{\tau_{C}}\right)
    \label{eq.05.RC.i.charging}
\end{equation}
For a capacitor with capacitance $C$, the amount of \textbf{voltage} $V_{C}$ across the \textbf{capacitor} is directly proportional to the amount of electric charge accumulated on the capacitor:
\begin{equation}
    V_{C}(t) = \frac{Q(t)}{C} = V_{\infty} \left[ 1 - \exp\left(-\frac{t}{\tau_{C}}\right) \right]
    \label{eq.05.RC.vC.charging}
\end{equation}
The \textbf{voltage} $V_{R}$ across the \textbf{resistor} is directly proportional the the amount of current, via Ohm's law:
\begin{equation}
    V_{R}(t) = R I(t) = V_{\infty} \exp\left(-\frac{t}{\tau_{C}}\right)
    \label{eq.05.RC.vR.charging}
\end{equation}
Here, $V_{\infty}$ is related to $Q_{\infty}$ and/or $I_{0}$ via
\begin{eqnarray}
    V_{\infty} = \frac{Q_{\infty}}{C} = I_{0} R
\end{eqnarray}
The value of $V_{\infty}$ should correspond to the steady voltage across the DC EMF source.

As you can see from Equation (\ref{eq.05.RC.q.charging}), Equation (\ref{eq.05.RC.i.charging}), and Equation (\ref{eq.05.RC.vC.charging}), the amount of charge, current and voltage related to a capacitor all involve exponential functions. The constant $\tau_{C}$ is known as the \textbf{capacitive time constant}. It has units of time (seconds). The value of $\tau_{C}$ sets a time scale for the change in values of charge, voltage, and current to occur. The same time scale appears in all three quantities. In an RC circuit, the value of $\tau_{C}$ depends on how much resistance $R$ and capacitance $C$ you have:
\begin{equation}
    \tau_{C} = R C
    \label{eq.05.tauC}
\end{equation}
You can check that, in fact, by multiplying something with ohm units by something with farad units you get something with second units:
\begin{equation}
    1 \ \text{ohm} \cdot 1 \ \text{F} = \left(1 \ \text{V {\textperiodcentered} s/C}\right) \cdot \left(1 \ \text{ C/V}\right) = 1 \ \text{s}
\end{equation}
Since the exponential function is a mathematical function that changes very fast, the current will take noise-level values after a time corresponding to about 5 capacitive time constants.
%
\subsubsection{Discharging the Capacitor}
%
After some time with the switch on, the amount of charge on the capacitor becomes almost constant (close to $Q_{\infty}$), the amount of voltage across the capacitor also becomes almost constant (close to $V_{\infty}$), and the current through the circuit becomes almost zero. Upon opening the circuit by setting the switch off, the DC EMF source stops supporting the charge accumulated on the capacitor, and that amount of charge begins to leave the capacitor. The amount of charge on the capacitor follows a particular manner:
\begin{equation}
    Q(t) = Q_{0} \exp\left(-\frac{t}{\tau_{C}}\right)
    \label{eq.05.RC.q.discharging}
\end{equation}
Here $Q_{0}$ is the amount of charge at the moment that the switch is turned off. The electric current is given by
\begin{equation}
    I(t) = - I_{0} \exp\left(-\frac{t}{\tau_{C}}\right)
    \label{eq.05.RC.i.discharging}
\end{equation}
This behavior is very similar to the behavior of the current (\ref{eq.05.RC.i.charging}) while the capacitor is charging, except that the negative sign indicates the current is in the opposite direction, since the charge is leaving the capacitor. The voltage $V_{C}$ across the \textbf{capacitor} can, again, be found from the amount of electric charge:
\begin{equation}
    V_{C}(t) = \frac{Q(t)}{C} = V_{0} \exp\left(-\frac{t}{\tau_{C}}\right)
    \label{eq.05.RC.vC.discharging}
\end{equation}
The capacitive time constant appears again, and also dictates the time scale for the decrease of the charge, current and voltage across the capacitor during the discharging event. The voltage $V_{R}$ across the \textbf{resistor} can, again, be found from the amount of electric current:
\begin{equation}
    V_{R}(t) = R I(t) = - V_{0} \exp\left(-\frac{t}{\tau_{C}}\right)
\end{equation}
Just as before, there is a relation between $Q_{0}$, $I_{0}$, and $V_{0}$:
\begin{equation}
    V_{0} = \frac{Q_{0}}{C} = I_{0} R
\end{equation}
The value of $V_{0}$ should correspond to the voltage across the capacitor just before the switch is opened.
%
\subsection{Resistor and Inductor in Series}
%
A circuit with a resistor, an inductor, and a DC EMF source is called an \textbf{RL circuit}. In the simplest RL circuit, the resistor and inductor are connected in series to the DC EMF source via a particular switch.

An \textbf{ideal inductor} is an inductor that has \textbf{zero electrical resistance}. In practice, the inductors that you will use in these experiments have a non-negligible amount of resistance that cannot be ignored and has to be taken into account. One way to do this is to think of a \textbf{non-ideal inductor} as consisting of a resistor and an ideal inductor connected in series:
\begin{equation}
    \text{non-ideal inductor} = \text{resistor} + \text{ideal inductor in series}
\end{equation}
Thus, an RL circuit with one resistor with resistance $R$ and one non-ideal inductor with resistance $r$ and inductance $L$ in series is equivalent to an RL circuit with \textbf{two} resistors and one ideal inductor in series. Let $V_{0}$ correspond to the EMF voltage produced by the DC EMF source in the RL circuit. Then, since the circuit is in series, the amount of EMF voltage from the DC EMF source must be equivalent to the sum of voltages across the two resistors and the ideal inductor:
\begin{equation}
    V_{0} = V_{R} + V_{r} + V_{L}
\end{equation}
Here, $V_{R}$ is the voltage across the main resistor, $V_{r}$ is the voltage across the resistor with the inductor resistance, and $V_{L}$ is the voltage across the ideal inductor. The problem is that you can directly measure $V_{R}$, but not $V_{L}$. Instead, measuring the voltage across the inductor gives the non-ideal total $V_{r} + V_{L}$. The other problem is that $V_{L}$ is what you really want, so $V_{r}$ has to be subtracted from the inductor measurement.

Although an inductor does not accumulate electric charge like a capacitor, the behavior of electric current and voltage across an inductor in an RL circuit also involves \textbf{exponential} functions.

Whereas in an RC circuit the current becomes zero for large time values after closing the switch, in an RL circuit the current rises to a steady value:
\begin{equation}
    I(t) = I_{\infty} \left[ 1 - \exp\left(- \frac{t}{\tau_{L}}\right) \right]
    \label{eq.05.RL.i.rise}
\end{equation}
The \textbf{voltage} $V_{R}$ across the main \textbf{resistor} is given by Ohm's law:
\begin{equation}
    V_{R}(t) = R I(t) = R I_{\infty} \left[ 1 - \exp\left(- \frac{t}{\tau_{L}}\right) \right]
    \label{eq.05.RL.vR}
\end{equation}
The \textbf{voltage} $V_{r}$ across the second resistor is also given by Ohm's law:
\begin{equation}
    V_{r}(t) = r I(t) = r I_{\infty} \left[ 1 - \exp\left(- \frac{t}{\tau_{L}}\right) \right]
    \label{eq.05.RL.vr}
\end{equation}
The \textbf{voltage} $V_{L}$ across the \textbf{inductor} is given by
\begin{equation}
    V_{L}(t) = V_{0} - V_{R}(t) - V_{r}(t) = V_{0} \exp\left(- \frac{t}{\tau_{L}}\right)
    \label{eq.05.RL.vL}
\end{equation}
Here $I_{\infty}$ and $V_{0}$ are related via
\begin{equation}
    V_{0} = I_{\infty} \left(R + r\right)
\end{equation}
Instead of $\tau_{C}$, you now have $\tau_{L}$ which corresponds to the \textbf{inductive time constant}. Just like $\tau_{C}$, the value of $\tau_{L}$ depends on the total amount of resistance and also on the inductance you have in the circuit:
\begin{equation}
    \tau_{L} = \frac{L}{R + r}
    \label{eq.05.tauL}
\end{equation}
You can check that in fact, by dividing something with henry units by something with ohm units you get something with second units:
\begin{equation}
    \frac{1 \ \text{H}}{1 \ \text{ohm}} = \frac{1 \ \text{ohm {\textperiodcentered} s}}{1 \ \text{ohm}} = 1 \ \text{s}
\end{equation}
%
\section{Experiment}
%
You did experiments for both RC and RL circuits.
%
\subsection{RC Circuits}
%
For RC circuits there are two kinds of events: the \textbf{charging} event and the \textbf{discharging} event. In each experiment you measured
\begin{itemize}
    \item the voltage across the \textbf{resistor}, $V_{R}(t)$;
    \item the current flowing between the resistor and the capacitor, $I(t)$; and
    \item the voltage across the \textbf{capacitor}, $V_{C}(t)$.
\end{itemize}
For the \textbf{charging event}, the data collection was started with the switch off (i.e. incomplete circuit) and shortly after turned on. You should analyze the \textbf{current} and the \textbf{voltage across the resistor} for such events.

For the \textbf{discharging event}, the data collection was started with the switch on (i.e. complete circuit) and shortly after turned off. You should analyze the \textbf{voltage across the capacitor} for such events.

There are many resistors and capacitors available. Each time the resistance or the capacitance changes, the time constant $\tau_{C}$ will also change.
%
\subsection{RL Circuits}
%
For RL circuits, all the experiments involved closing the switch after the data collection started. You measured
\begin{itemize}
    \item the voltage across the resistor, $V_{R}(t)$;
    \item the current flowing between the resistor and the non-ideal inductor, $I(t)$; and
    \item the voltage across the non-ideal inductor, $V_{r}(t) + V_{L}(t)$.
\end{itemize}
Because the inductive time constants are so small, the data acquisition needs to be activated with the trigger feature.

The inductors come with a \textbf{metallic core}. Each experiment is done twice: Once without the core, and once with the core. The effect of the core is to change the inductance of the inductor.

There are many resistors, and many ways to connect inductors of the same type. Each time the resistance or the inductance changes, the time constant $\tau_{L}$ will also change.
%
\section{Analysis}
%
The common feature of $f(t)$, $g(t)$, and $h(t)$ above is that they all settle on steady values for infinite time after $t = 0$. In an experiment, you do not have an infinite amount of time, so a relevant question is how long corresponds to infinite time. Since you are using imperfect sensors to measure current and voltage, after some time of decreasing towards zero, there will be a point where measurements are not distinguishable from noise.

Consider the following function:
\begin{equation}
    A(t) = A_{0} \exp\left(- \frac{t}{\tau}\right)
\end{equation}
At $t = 0$, you have
\begin{equation}
    A(0) = A_{0}
\end{equation}
Thus, $A_{0}$ correspond to the amount of $A$ present at $t = 0$. The value of $A$ after one unit of $\tau$ is:
\begin{equation}
    A(\tau) = A_{0} \exp\left(-1\right) = 0.3679 \cdot A_{0}
\end{equation}
That is, about 37\% of the starting value. After two units of $\tau$ you have:
\begin{equation}
    A(2\tau) = A_{0} \exp\left(-2\right) = 0.1353 \cdot A_{0}
\end{equation}
That is, about 14\% of the starting value. After three units of $\tau$ you have:
\begin{equation}
    A(3\tau) = A_{0} \exp\left(-3\right) = 0.0498 \cdot A_{0}
\end{equation}
That is, about 5\% of the starting value. After four units of $\tau$ you have:
\begin{equation}
    A(4\tau) = A_{0} \exp\left(-4\right) = 0.0183 \cdot A_{0}
\end{equation}
That is, about 2\% of the starting value. After five units of $\tau$ you have:
\begin{equation}
    A(5\tau) = A_{0} \exp\left(-5\right) = 0.0067 \cdot A_{0}
\end{equation}
That is, about 0.67\% of the starting value. Five units of $\tau$ is a good rule of thumb. In principle, the quantity that is being measured will continue decreasing in value, but in practice those small values cannot be reliably measured. If you have an estimate of the amount of $\tau$, then from the time the decay begins you should unlike keep until after $5 \tau$ has passed.
%
\subsection{RC Circuits: Charging Events}
%
In a charging event, both the voltage across the resistor and the current decay exponentially. Here are some steps to follow:
%
\subsubsection{Visualize $V_{R}$ and $I$}
%
Make two scatter charts:
\begin{itemize}
    \item Voltage across the resistor in the vertical axis, and time in the horizontal axis.
    \item Current in the vertical axis, and time in the horizontal axis.
\end{itemize}
You might want to add exponential fits, although at this stage they would most likely not be appropriate. See Figure \ref{figure.05.run.1.vR.full} for an example.
%
\subsubsection{Truncate the part before closing circuit}
%
Before the exponential fit can be made meaningful, you need to truncate the part of the data before the switch is closed. Looking at the columns, it should be obvious when the values for $V_{R}$ and $I$ suddenly take large values. See Figure \ref{figure.05.run.1.vR.truncated} for an example after truncation.
%
\subsubsection{Truncate the long tail}
%
It is very likely that after removing the part of the data before closing the circuit, the exponential fit might still not be appropriate. If the decay is relatively quick, and the voltage or current has a long segment where it is just zero, that long tail section will skew the fit process and render incorrect results. For this reason, it is good to only keep a time segment that is about $5\tau_{C}$ long. For example, after truncation in Figure \ref{figure.05.run.1.vR.truncated}, the decay begins around $t = 1.85$ seconds. For this particular run, the expected value of the time constant is $\tau_{C} = 0.250$ seconds. Thus,
\begin{equation}
    1.85 \text{ s} + 5 \tau_{C} = 3.10 \text{ s}
\end{equation}
All the data after $t = 3.10$ seconds should be truncated also. For good measure, I am keeping everything up to $t = 3.20$ seconds. See Figure \ref{figure.05.run.1.vR.no.tail} for an example.
%
\subsubsection{Extract the experimental value of $\tau_{C}$}
%
After truncating the initial and long tail parts, the exponential fit should be appropriate for the data. The exponential fit is given in the form
\begin{equation}
    a \exp(-bx)
\end{equation}
The value of $b$ corresponds to the inverse of the time constant:
\begin{equation}
    b = \frac{1}{\tau_{C}}
\end{equation}
Thus, the observed value of the time constant follows from the inverse of $b$:
\begin{equation}
    \text{Observed} \ \tau_{C} = \frac{1}{b}
\end{equation}
You should get a value from the $V_{R}$ chart, and another value from the $I$ chart. Both values should be consistent with each other.
%
\subsection{RC Circuits: Discharging Events}
%
In the discharging event, only the voltage across the capacitor follows an exponential decay. The steps are similar:
\begin{enumerate}
    \item Visualize the data with a scatter chart with the voltage across the capacitor in the vertical axis, and time in the horizontal axis.
    \item Truncate the part before opening the circuit.
    \item Truncate the long tail and keep close to $5\tau_{C}$ after the time the decay begins.
    \item Extract the experimental value of $\tau_{C}$ from the fit equation.
\end{enumerate}
The value of $\tau_{C}$ for the discharging event should be consistent with the value for the charging event.
%
\subsection{RL Circuits: Resistance of Inductors}
%
Before dealing with the inductive time constant experiments, you have to determine how much electrical resistance does the non-ideal inductors that are available have. Just like for resistors, in order to measure resistance you obtain current and voltage data over time. Using
\begin{equation}
    r = \frac{V_{r}(t)}{I(t)}
\end{equation}
should provide the observed value of the resistance of the non-ideal inductor over time. This value should be steady and almost constant, so take a time average to get the best estimate.

For two non-ideal inductors in series, you should find that the resistance is close to double the resistance for a single non-ideal inductor in series.
%
\subsection{RL Circuits: Inductive Time Constant}
%
For these experiments you measured the voltage $V_{R}(t)$ across the resistor, the current $I(t)$ between the resistor and the non-ideal inductor, and the voltage $V_{r}(t) + V_{L}(t)$ across the non-ideal inductor.

As Figure \ref{figure.05.vL.nonideal.full} shows, the voltage across the non-ideal inductor does not decay exponentially. The only quantity that decays exponentially is the voltage $V_{L}(t)$ across the ideal inductor. In order to obtain this, you have to subtract the voltage $V_{r}(t)$ due to the resistance of the non-ideal inductor from the signal. The voltage due to the resistance of the inductor is given by
\begin{equation}
    V_{r}(t) = r I(t)
\end{equation}
Here, $r$ is the resistance of the non-ideal inductor. You measured this in the previous section. You should calculate this in a separate column, and then subtract this from the column with the voltage across the non-ideal inductor. After this subtraction, the data should show an exponential decay curve that approaches zero. See Figure \ref{figure.05.vL.full}. After removing the long tail, the exponential fit becomes appropriate. See Figure \ref{figure.05.run.1.vL}.
%
\section{My Data}
%
For the RC circuits, my data consist of twelve runs:
\begin{itemize}
    \item Run 1: Charging capacitor with $R = 10$ ohm and $C = 2.5 \times 10^{-2}$ F.
	\item Run 2: Discharging capacitor with $R = 10$ ohm and $C = 2.5 \times 10^{-2}$ F.
	\item Run 3: Charging capacitor with $R = 51$ ohm and $C = 2.5 \times 10^{-2}$ F.
	\item Run 4: Discharging capacitor with $R = 51$ ohm and $C = 2.5 \times 10^{-2}$ F.
	\item Run 5: Charging capacitor with $R = 68$ ohm and $C = 2.5 \times 10^{-2}$ F.
	\item Run 6: Discharging capacitor with $R = 68$ ohm and $C = 2.5 \times 10^{-2}$ F.
	\item Run 7: Charging capacitor with $R = 4.7 \times 10^{4}$ ohm and $C = 10^{-5}$ F.
	\item Run 8: Discharging capacitor with $R = 4.7 \times 10^{4}$ ohm and $C = 10^{-5}$ F.
	\item Run 9: Charging capacitor with $R = 10^{5}$ ohm and $C = 10^{-5}$ F.
	\item Run 10: Discharging capacitor with $R = 10^{5}$ ohm and $C = 10^{-5}$ F.
	\item Run 11: Charging capacitor with $R = 2.2 \times 10^{4}$ ohm and $C = 10^{-5}$ F.
	\item Run 12: Discharging capacitor with $R = 2.2 \times 10^{4}$ ohm and $C = 10^{-5}$ F.
\end{itemize}
For the RL circuits, my data consist of eight runs:
\begin{itemize}
    \item Run 1: $R = 10$ ohm, one inductor without metallic core ($L = 0.005$ H).
    \item Run 2: $R = 10$ ohm, one inductor with metallic core (unknown $L$).
    \item Run 3: $R = 5$ ohm, one inductor without metallic core ($L = 0.005$ H).
    \item Run 4: $R = 5$ ohm, one inductor with metallic core (unknown $L$).
    \item Run 5: $R = 10$ ohm, two inductors without metallic core ($L = 0.01$ H).
    \item Run 6: $R = 10$ ohm, two inductors with metallic core (unknown $L$).
    \item Run 7: $R = 5$ ohm, two inductors without metallic core ($L = 0.01$ H).
    \item Run 8: $R = 5$ ohm, two inductors with metallic core (unknown $L$).
\end{itemize}
%
\subsection{RC Circuits}
%
My results for the RC circuits are summarize in Table \ref{table.05.results.tauC.VR}, Table \ref{table.05.results.tauC.I}, and Table \ref{table.05.results.tauC.VC}. As you can see, the results are consistent with each other, and somewhat consistent with the expected value of the capacitive time constant. Indeed, when the resistance is increased, the observed time constant also increases. It is interesting that the results from the voltage across the resistor are not as accurate as the results for the voltage across the capacitor.
%
\subsection{RL Circuits}
%
The results for the inductive time constant from the voltage across the ideal inductor are in Table \ref{table.05.results.tauL.VL}. As you can see, the effect of using the metallic core is to increase the inductance. When you decrease the resistance, the time constant becomes larger.
%
\section{Your Data}
%
For the RC circuits, your data will consist of the following runs:
\begin{itemize}
    \item Run 1: Charging capacitor with $R = 10$ ohm and $C = 2.5 \times 10^{-2}$ F.
	\item Run 2: Discharging capacitor with $R = 10$ ohm and $C = 2.5 \times 10^{-2}$ F.
	\item Run 3: Charging capacitor with either $R = 51$ ohm or $R = 68$ ohm and $C = 2.5 \times 10^{-2}$ F.
	\item Run 4: Discharging capacitor with either $R = 51$ ohm or $R = 68$ ohm and $C = 2.5 \times 10^{-2}$ F.
	\item Run 5: Charging capacitor with either $R = 2.2 \times 10^{4}$ ohm or $R = 4.7 \times 10^{4}$ ohm and $C = 10^{-5}$ F.
	\item Run 6: Discharging capacitor with either $R = 2.2 \times 10^{4}$ ohm or $R = 4.7 \times 10^{4}$ ohm and $C = 10^{-5}$ F.
\end{itemize}
For the inductor resistance part, your data will consist of the following runs:
\begin{itemize}
    \item Run 1: One inductor without metallic core.
    \item Run 2: One inductor with metallic core.
    \item Run 3: Two inductors in series without metallic cores.
    \item Run 4: Two inductors in series with metallic cores.
\end{itemize}
For the RL circuits, your data will consist of the following runs:
\begin{itemize}
    \item Run 1: One $R = 10$ ohm resistor, and one inductor without metallic core.
    \item Run 2: One $R = 10$ ohm resistor, and one inductor with metallic core.
    \item Run 3: One $R = 10$ ohm resistor, and two inductors in series without metallic core.
    \item Run 4: One $R = 10$ ohm resistor, and two inductors in series with metallic core.
    \item Run 5: Two $R = 10$ ohm resistors in parallel, and one inductor without metallic core.
    \item Run 6: Two $R = 10$ ohm resistors in parallel, and one inductor with metallic core.
    \item Run 7: Two $R = 10$ ohm resistors in parallel, and two inductors in series without metallic core.
    \item Run 8: Two $R = 10$ ohm resistors in parallel, and two inductors in series with metallic core.
\end{itemize}
%
% \newpage
% \section{Your Lab Report}
% %
% Your report should include the following:
% \begin{itemize}
%     \item A table like Table \ref{table.05.results.tauC.VR} with the results for $\tau_{C}$ from the voltage across the resistor for charging events.
%     \item A table like Table \ref{table.05.results.tauC.I} with the results for $\tau_{C}$ from the current for charging events.
%     \item A table like Table \ref{table.05.results.tauC.VC} with the results for $\tau_{C}$ from the voltage across the capacitor for discharging events.
%     \item For a charging event, one chart with the voltage across the resistor in the vertical axis, and time in the horizontal axis. Like in Figure \ref{figure.05.run.1.vR.no.tail}, include the exponential fit, the equation for the fit, and remove the head and tail parts of the data.
%     \item For a charging event, one chart with the current in the vertical axis, and time in the horizontal axis. Include the exponential fit, the equation for the fit, and remove the head and tail parts of the data.
%     \item For a discharging event, one chart with the voltage across the capacitor in the vertical axis, and time in the horizontal axis. Include the exponential fit, the equation for the fit, and remove the head and tail parts of the data.
%     \item A table like Table \ref{table.05.results.tauL.VL} with the results for $\tau_{L}$ from the voltage across the ideal inductor.
%     \item One chart with the voltage across the ideal inductor in the vertical axis, and time in the horizontal axis. Include the exponential fit, the equation for the fit, and remove the long tail part of the data.
% \end{itemize}
% You should answer the following questions:
% \begin{enumerate}
%     \item Are the experimental values of $\tau_{C}$ from $V_{R}(t)$ and $I(t)$ consistent in a charging event?
%     \item Is the value of $\tau_{C}$ from $V_{C}(t)$ in a discharging event consistent with the values obtained in the charging event with same resistor and capacitor?
%     \item Why is the current data not usable when the resistors with thousands of ohms worth of resistance used?
%     \item What is the resistance value for one non-ideal inductor?
%     \item Does the metallic core change substantially the value of the resistance of a non-ideal inductor?
%     \item What happens to the value of $\tau_{L}$ when the metallic core is used?
%     \item What happens to the value of $\tau_{L}$ when the two resistors are connected in series, but one inductor is used?
%     \item What happens to the value of $\tau_{L}$ when one resistor is used, but the two inductors are connected in series?
% \end{enumerate}
%
\newpage
\section{Tables}
%
\begin{table}[ht]
    \centering
    \begin{tabular}{l|r|r|r|r|r}
        \textbf{Run} & $R$ (ohm) & $C$ (F) & \textbf{Expected} $\tau_{C}$ (s) & \textbf{Observed} $\tau_{C}$ (s) & \textbf{P.D.} (\%) \\
        \hline
        1 & 10 & 2.5 {\texttimes} 10\textsuperscript{\textminus 2} & 0.250 & 0.298 & 19.05 \\
        3 & 51 & 2.5 {\texttimes} 10\textsuperscript{\textminus 2} & 1.275 & 1.416 & 11.09 \\
        5 & 68 & 2.5 {\texttimes} 10\textsuperscript{\textminus 2} & 1.700 & 1.848 & 8.73 \\
        7 & 4.7 {\texttimes} 10\textsuperscript{4} & 10\textsuperscript{\textminus 5} & 0.470 & 0.606 & 28.95 \\
        9 & 10\textsuperscript{5} & 10\textsuperscript{\textminus 5} & 1.000 & 1.238 & 23.76 \\
        11 & 2.2 {\texttimes} 10\textsuperscript{4} & 10\textsuperscript{\textminus 5} & 0.220 & 0.253 & 15.07 \\
        \hline
    \end{tabular}
    \caption{Results for $\tau_{C}$ from $V_{R}$}
    \label{table.05.results.tauC.VR}
\end{table}
%
\begin{table}[ht]
    \centering
    \begin{tabular}{l|r|r|r|r|r}
        \textbf{Run} & $R$ (ohm) & $C$ (F) & \textbf{Expected} $\tau_{C}$ (s) & \textbf{Observed} $\tau_{C}$ (s) & \textbf{P.D.} (\%) \\
        \hline
        1 & 10 & 2.5 {\texttimes} 10\textsuperscript{\textminus 2} & 0.250 & 0.298 & 19.05 \\
        3 & 51 & 2.5 {\texttimes} 10\textsuperscript{\textminus 2} & 1.275 & 1.403 & 10.00 \\
        5 & 68 & 2.5 {\texttimes} 10\textsuperscript{\textminus 2} & 1.700 & 1.842 & 8.33 \\
        \hline
    \end{tabular}
    \caption{Results for $\tau_{C}$ from $I$}
    \label{table.05.results.tauC.I}
\end{table}
%
\begin{table}[ht]
    \centering
    \begin{tabular}{l|r|r|r|r|r}
        \textbf{Run} & $R$ (ohm) & $C$ (F) & \textbf{Expected} $\tau_{C}$ (s) & \textbf{Observed} $\tau_{C}$ (s) & \textbf{P.D.} (\%) \\
        \hline
        2 & 10 & 2.5 {\texttimes} 10\textsuperscript{\textminus 2} & 0.250 & 0.264 & 5.54 \\
        4 & 51 & 2.5 {\texttimes} 10\textsuperscript{\textminus 2} & 1.275 & 1.366 & 7.15 \\
        6 & 68 & 2.5 {\texttimes} 10\textsuperscript{\textminus 2} & 1.700 & 1.792 & 5.42 \\
        8 & 4.7 {\texttimes} 10\textsuperscript{4} & 10\textsuperscript{\textminus 5} & 0.470 & 0.559 & 18.86 \\
        10 & 10\textsuperscript{5} & 10\textsuperscript{\textminus 5} & 1.000 & 1.193 & 19.33 \\
        12 & 2.2 {\texttimes} 10\textsuperscript{4} & 10\textsuperscript{\textminus 5} & 0.220 & 0.259 & 17.76 \\
        \hline
    \end{tabular}
    \caption{Results for $\tau_{C}$ from $V_{C}$}
    \label{table.05.results.tauC.VC}
\end{table}
%
\begin{table}[ht]
    \centering
    \begin{tabular}{l|r|r|r|r|r}
        \textbf{Run} & $R + r$ (ohm) & $L$ (H) & \textbf{Expected} $\tau_{L}$ (s) & \textbf{Observed} $\tau_{L}$ (s) & \textbf{P.D.} (\%) \\
        \hline
        1 & 10 + 4.17 & 5 {\texttimes} 10\textsuperscript{\textminus 3} & 3.53 {\texttimes} 10\textsuperscript{\textminus 4} & 3.50 {\texttimes} 10\textsuperscript{\textminus 4} & \textminus 0.74 \\
        2 & 10 + 4.17 & N.A. & N.A. & 1.59 {\texttimes} 10\textsuperscript{\textminus 3} & N.A. \\
        3 & 5 + 4.17 & 5 {\texttimes} 10\textsuperscript{\textminus 3} & 5.45 {\texttimes} 10\textsuperscript{\textminus 4} & 5.48 {\texttimes} 10\textsuperscript{\textminus 4} & 0.49 \\
        4 & 5 + 4.17 & N.A. & N.A. & 2.36 {\texttimes} 10\textsuperscript{\textminus 3} & N.A. \\
        \hline
    \end{tabular}
    \caption{Results for $\tau_{L}$ from $V_{L}$}
    \label{table.05.results.tauL.VL}
\end{table}
%
\newpage
\section{Figures}
%
\begin{figure}[ht]
    \centering
    \includegraphics[scale=0.74]{image/05-RC-RL/f.pdf}
    \caption{Function $f(t)$}
    \label{figure.05.f}
\end{figure}
%
\begin{figure}[ht]
    \centering
    \includegraphics[scale=0.74]{image/05-RC-RL/g.pdf}
    \caption{Function $g(t)$}
    \label{figure.05.g}
\end{figure}
%
\begin{figure}[ht]
    \centering
    \includegraphics[scale=0.74]{image/05-RC-RL/h.pdf}
    \caption{Function $h(t)$}
    \label{figure.05.h}
\end{figure}
%
\begin{figure}[ht]
    \centering
    \includegraphics[scale=0.74]{image/05-RC-RL/run-1-vR-full.pdf}
    \caption{Run 1: $V_{R}(t)$}
    \label{figure.05.run.1.vR.full}
\end{figure}
%
\begin{figure}[ht]
    \centering
    \includegraphics[scale=0.74]{image/05-RC-RL/run-1-vR-truncated.pdf}
    \caption{Run 1: $V_{R}(t)$}
    \label{figure.05.run.1.vR.truncated}
\end{figure}
%
\begin{figure}[ht]
    \centering
    \includegraphics[scale=0.74]{image/05-RC-RL/run-1-vR-no-tail.pdf}
    \caption{Run 1: $V_{R}(t)$}
    \label{figure.05.run.1.vR.no.tail}
\end{figure}
%
\begin{figure}[ht]
    \centering
    \includegraphics[scale=0.74]{image/05-RC-RL/vL-non-ideal-full.pdf}
    \caption{Run 1: $V_{r}(t) + V_{L}(t)$}
    \label{figure.05.vL.nonideal.full}
\end{figure}
%
\begin{figure}[ht]
    \centering
    \includegraphics[scale=0.74]{image/05-RC-RL/vL-full.pdf}
    \caption{Run 1: $V_{L}(t)$}
    \label{figure.05.vL.full}
\end{figure}
%
\begin{figure}[ht]
    \centering
    \includegraphics[scale=0.74]{image/05-RC-RL/run-1-vL.pdf}
    \caption{Run 1: $V_{L}(t)$}
    \label{figure.05.run.1.vL}
\end{figure}


\chapter{Introduction}
\label{chap:chapter1}
\pagenumbering{arabic}\hspace{3mm}

The basic job of a compiler is code translation from a high level
language to a target assembly language. But, compilers also run
multiple optimization pass in the intermediate stages of translation,
so that the finally generated code performs better than just a normal
translated code. There might be a one time overhead of
running optimizations, but the performance gain visible over multiple
executions of the code outweighs it.

Modern compilers performs a large number of optimizations like
induction variable analysis, loop interchange, loop invariant code
motion, loop unrolling, global value numbering, dead code
optimizations, constant folding and propagation, common subexpression
elimination etc. One common feature of most of these optimizations is
detecting equivalent program subexpressions.

Checking equivalence of program subexpressions has been shown to be
an undecidable problem, even when all the conditional statements are
considered as non deterministic. So, in most of the cases compilers
try to find some restricted form of expression equivalence. One such
form of expression equivalence is \textbf{Herbrand Equivalence} (see section \ref{sec:HerbrandEquivalence}).
Detecting equivalence of program subexpressions can be used for
variety of applications. Compilers can use these to perform several
of the optimizations mentioned above like constant propagation,
common subexpression elimination etc. Program verification tools can
use these equivalences to discover loop invariants and to verify
program assertions. This information is also important for discovering
equivalent computations in different programs, which can be used by
plagiarism detection tools and translation validation tools \cite
{Necula, Pnueli}, which compare a program with an optimized version
in order to check correctness of the optimizer.

\section{Herbrand Equivalence}
\label{sec:HerbrandEquivalence}
A formal definition of \textbf{Herbrand Equivalence} is given in
\cite{Ruthing}.
Informally, two expressions are \textbf{Herbrand equivalent at a program
point}, if and only if they have syntactically the same value at that
particular point, \textbf{across all the execution paths} from the start
of the program which reaches that point. For the purpose of analysis,
the operators themselves are treated as uninterprated functions with
no semantic significance, only syntactic information is taken into
consideration (see \ref{sec:ASimpleExample}{example below}).

For \textbf{Herbrand equivalence analysis}, we consider the set of all
possible expressions that can be formed using the constants,
variables and operators used in the program. And for each program
point, partition them such that two expressions are Herbrand
equivalent at that point if and only if they belong to the same
partition class for that point.

\section{A Simple Example}
\label{sec:ASimpleExample}

\begin{figure}[!ht]
\label{fig:HerbrandEquivalenceTrans}
    \centering {
        \setlength{\fboxsep}{8pt}
        \fbox{\includegraphics[scale=0.55]{HerbrandEquivalenceTrans.png}}
    }
    \caption{Example of Herbrand Equivalence}
\end{figure}

Figure \ref{fig:HerbrandEquivalenceTrans} shows a simple example of Herbrand Equivalence analysis. All the expressions that belongs to the same set at a program point are Herbrand equivalent at that point.
\begin{itemize}
    \item   Initially all the expressions are in separate sets, ie.
    they are inequivalent to each other. In particular, note that
    $X + 2$ and $2 + X$ are inequivalent because the operators are
    being treated uninterprated with no semantic information of them,
    which means there is no knowledge of commutativity of $+$.
    \item   After assignment $X = 2$, any occurrence of $X$ in an
    expression can be replaced with $2$. So, now all expressions with
    $2$ in place of $X$ and vice versa are equivalent - that means
    $2 + 2$, $2 + X$, $X + 2$, $X + X$ are all equivalent - this still
    is just syntactic information because $X$ and $2$ are equivalent.
    However, if $4$ was also in the universe of expressions, $2 + 2$ and
    $4$ are not equivalent as this is semantic information of $+$.
    \item   After assignment $Y = X$, any occurrence of $Y$ in
    an expression can be replaced with $X$. Because $X$ and $2$ are already
    equivalent, it means now $2$, $X$, and $Y$ are all equivalent to
    each other. And two expressions are equivalent if one can be
    obtained from the other by replacing one of these with any of the
    other two. For this example, it means that two expressions of
    the same length are equivalent.
\end{itemize}

\begin{figure}[!ht]
\label{fig:HerbrandEquivalenceConv}
    \centering {
        \setlength{\fboxsep}{8pt}
        \fbox{\includegraphics[scale=0.54]{HerbrandEquivalenceConv.png}}
    }
    \caption{Example of Herbrand Equivalence analysis at a confluence point}
\end{figure}

Figure \ref{fig:HerbrandEquivalenceConv} shows what happens at a
\textbf{confluence point} - a point where multiple paths meet. Two
expressions are Herbrand equivalent only if they are Herbrand
equivalent at all the predecessor points.
\begin{itemize}
    \item   In the left branch $2$, $Y$, $Z$ are equivalent and
    so are expressions which are interconvertible by replacement
    of any of these three, with any other.
    \item   The case with the right branch is similar, except $X$ is
    equivalent to $2$ and $Z$ instead of $Y$.
    \item   At the confluence point, only $2$ and $Z$ are equivalent
    because they were equivalent at both the predecessors points. $X$
    was equivalent to $2$ and $Z$ at the right predecessor but not
    the left one and $Y$ was equivalent to $2$ and $Z$ at the left
    predecessor but not the right. As before, expressions obtained by
    replacing $2$ with $Z$ and vice versa are equivalent.
\end{itemize}

\section{Goal of the Project}
\label{sec:GoalOfTheProject}
\cite{Babu} gives an algorithm for Herbrand Equivalence analysis
restricted to program expressions. The basic goal of this project
is to refine this general algorithm and then implement it for
\href{https://llvm.org/}{Clang-LLVM compiler}; then extend this
algorithm to use the analysis information for performing actual program
optimizations. Finally, a proof of correctness of the algorithm has
to be presented which would also be based on the work in \cite{Babu}.

\section{Organization of the Report}
\label{sec:OrganizationOfTheReport}
Chapter \ref{chap:chapter2} gives a brief overview of previous works
related to the Herbrand Equivalence; then summary of the
papers \cite{Gulwani, Saleena, Babu} are specifically presented. Chapter
\ref{chap:chapter6} provides a tutorial on writing an LLVM
optimzation pass. Chapter \ref{chap:chapter7} gives pseudocode for Herbrand
Equivalence analysis of a program; algorithms in chapter \ref{chap:chapter8}
extends these to use the analysis information for performing actual program
optimizations.


\documentclass[11pt,a4paper]{amsart}

\begin{document}

\begin{center}
   \bf Note on the Exponential Cell Matrix
\end{center}

\bigskip

This brief note is to recap the deformation of a cell matrix via the matrix
exponential (Lie group). First of all, we don't work in terms of the cell matrix
$C$, but in terms of its transpose $A = C^T$. We will then write
%
\[
  A = \exp(U) A_0,
\]
where $A_0$ is some reference cell matrix.

\subsection*{Virial and Stress}
%
First, however, we recap the definition of virial and of stress. Let $R$ be the
current positions and $A = C^T$ the current cell matrix. When we deform the cell
matrix, then the positions deform accordingly,
%
\[
   A \mapsto F \cdot A \quad \Rightarrow \quad R \mapsto F \cdot R.
\]
The (negative) virial is the derivative of the PES with respect to $F$
under this transformation. That is, if $E(A, R)$ denotes the PES with
cell matrix $A$ and positions $R$ then
\[
   - T^{\rm vir}_{i\alpha} := \frac{\partial}{\partial F_{i\alpha}}
      E( F A, F R ) \Big|_{F = I}.
\]
For example, for a pair potential,
\[
   E = \frac12 \sum_{a \neq b} \phi(r_{ab}),
\]
with this definition we obtain
\[
   T^{\rm vir} = - \frac12 \sum_{a \neq b} \phi'(r_{ab}) R_{ab} \otimes R_{ab},
\]
which should be the correct definition. (For EAM the expression is analogous, in general it can be a bit more complex.)

We can connect this to the Piola--Kirchhoff and Cauchy stresses as follows: Let
$A_0$ be some reference cell matrix, and $R_0$ the reference cell positions and
let $A = F A_0, R = F R_0$, then the Cauchy--Born energy per unit (underformed)
volume is
\[
   W(F) = (\det A_0)^{-1} E(F A_0, F R_0)
\]
and its derivative $T^{\rm pk} := \partial_F W(F)$ is the first Piola--Kirchhoff
stress. For a pair potential this can be readily calculated as
%
\begin{equation} \label{eq:Tpk-pair}
   T^{\rm pk} = \frac12 \sum_{a \neq b} \phi'(r_{ab}) R_{ab} \otimes R_{0,ab};
\end{equation}
%
(i.e., $r_{ab} = |F R_{0,ab}|$ and $R_{ab} = F R_{0,ab}$) note in particular
that this is asymmetric.

The Cauchy--Stress is given by
\[
   T^{\rm pk} = T^{\rm c} {\rm cof} F,
\]
where ${\rm cof} F = {\rm det F} F^{-T}$,  that is,
\[
   T^{\rm c} = (\det F)^{-1} T^{\rm pk} F^T.
\]
%
Returning to the example of a pair potential, inserting this expression into
\eqref{eq:Tpk-pair}, recalling $A = F A_0, R = F R_0$ and using $\det A_0 \det F
= \det (F A_0) = \det A$,  we obtain
%
\begin{align*}
   T^{\rm c} &= (\det A_0 \det F)^{-1} \sum_{a \neq b} \phi'(r_{ab}) (F R_{0,ab}) \otimes (F R_{0,ab})  \\
   &= (\det A)^{-1} \sum_{a \neq b} \phi'(r_{ab}) R_{ab} \otimes R_{ab} \\
   &= - (\det A)^{-1} T^{\rm vir}.
\end{align*}
%
In general, we take this as the definition of atomistic (Cauchy) stress:
%
\begin{equation} \label{eq:defn-at-stress}
   T^{\rm c} := - (\det A)^{-1} T^{\rm vir},
\end{equation}
i.e., negative virial normalised with respect to deformed cell volume.

\subsection*{Cell Deformation via Exponential Map}
%
We are now simply replacing the cell deformation  $A_0 \mapsto F A_0$ with $A_0
\mapsto \exp(U) A_0$. More generally, we allow a cell matrix $A = \exp(U) A_0$
and positions $R = \exp(U) R_0$ and consider the PES $E$ as a function of $U$
and $R$, hence we need to compute
%
\begin{align*}
   T^{\rm log}_{i\alpha}
   &:=  \frac{\partial}{\partial U_{i\alpha}} E\big( \exp(U) A_0, \exp(U) R_0 \big) \\
   &= \frac{\partial}{\partial V_{i\alpha}} E\big( \exp(V) A, \exp(V) R \big) \Big|_{V = 0}.
\end{align*}
There are several ways to derive an expression, we will first start from the
virial.

Let $L(U, V) := \partial \exp(U) : V$ be the linearisation of the exponential
map, that is,
\[
   L(U, V) := \frac{d}{dt} \exp(U + t V) \Big|_{t = 0},
\]
then writing $F = \exp(V)$ and applying the chain rule we clearly have
%
\begin{align*}
   T^{\rm log} : V = T^{\rm log}_{i\alpha} V_{i\alpha}
   &=
   \big(-T^{\rm vir}_{j\beta}\big)\,
   \frac{\partial F_{j\beta}}{\partial V_{i\alpha}} |_{V=0} V_{i\alpha} \\
   &=
   - T^{\rm vir}_{j\beta} \, \big[L(0, V) \big]_{j\beta}
   = - T^{\rm vir} : L(0, V).
\end{align*}
Since $\exp(V) = I + V + O(V^2)$ it follows that $L(0, V) = V$, and hence we
simply have
\[
   T^{\rm log} = - T^{\rm vir}.
\]
We could have just guessed this, since for infinitesimal $V$ we just
have $\exp(V) \sim I + V$. The exponential map becomes important
only when we allow large deformations.

\subsection*{Geometry Optimisation}
%
In geometry optimisation it is not always convenient to compute gradients in the
deformed configuration, but to fit within the standard optimisation frameworks
it can be expedient to freeze some reference configuration and represent the
deformed configuration in terms of that reference. In {\tt JuLIP} this is done
as follows (but other choices are possible and may indeed be better!):
%
\begin{itemize}
   \item At the beginning of the optimisation a reference cell $A_0$ and reference positions $R_0$ are frozen.
   \item Given a current configuration $A, R$ we represent it
   as
   \[
      A = \exp(U) A_0 \qquad \text{and} \qquad
      R = \exp(U) X
   \]
   \item We take $(U, X)$ as the degrees of freedom with respect to which we
   optimise. We also enforce that $U$ is symmetric. Any anti-symmetric component
   corresponds to a rotation and does not change the energy of the system.
\end{itemize}
%
Let $\Phi(U, X) := E(A, R)$ then we need to compute $\nabla_U \Phi, \nabla_X
\Phi$. We begin with the latter: since $R_i = \exp(U) X_i$ we simply have
\[
   \nabla_{X_i} \Phi = \bigg[\frac{\partial R_i}{\partial X_i}\bigg]^T \nabla{R_i} E
      = \exp(U) \nabla_{R_i} E,
\]
where $\nabla_{R_i} E$ is the negative force acting on atom $i$. Here, we also
employed our assumption that $U$ is symmetric.

We now turn towards $\nabla_{U} \Phi$. Note that we have $\Phi(U, X) := E(A, R)
= E(\exp(U) A_0, \exp(U) X)$, that is, computing $\nabla_U \Phi$ is similar to
the computation of the Piola--Kirchhoff stress, except for the volume
normalisation; that is, with $F = \exp(U)$ we have
\begin{align*}
   \nabla_U \Phi : V
   &=
   (\partial_{U_{i\alpha}} \Phi)\, V_{i\alpha} \\
   %
   &=
   \partial_{F_{j\beta}} E(F A_0, F X)
   \frac{\partial F_{j\beta}}{\partial U_{i\alpha}} V_{i\alpha} \\
   %
   &=
   \big[ (\det A_0) T^{\rm pk} \big]_{j\beta} \big[L(U, V)\big]_{j\beta} \\
   %
   &=
   \big[ - T^{\rm vir} \exp(-U) \big]_{j\beta} \big[L(U, V)\big]_{j\beta} \\
   %
   &=
   - \big[ T^{\rm vir} \exp(-U) \big] : L(U, V).
\end{align*}
Finally, it only remains to observe that
\[
   G : L(U, V) = V : L(U, G),
\]
which can be proven directly by manipulating the series representation to obtain
that
\begin{equation} \label{eq:grad_U}
   \nabla_U \Phi = - L(U, T^{\rm vir} \exp(-U)).
\end{equation}

\end{document}


\chapter{Atomic Units}
\label{chap:atomic-units}

\singlespacing

This thesis uses, throughout the text, the atomic system of units, unless otherwise specified (such as explicit indications of wavelengths, intensities, or photoelectron energies). The atomic system of units is specifically designed to make the electronic hamiltonian for an atom less cumbersome in terms of constants. More concretely, this is achieved by setting to unity the main (dimensionful) physical constants of the quantum dynamics of an electron,
\begin{equation}
m_e=1
,\quad
\hbar=1
,\quad
e^2=1
,\quad\text{and}\quad
k_\mathrm{c} = \frac{1}{4\pi\eps_0}=1
.
\end{equation}
As a result, the dynamics becomes essentially dimensionless, though after identifying the physical dimension of a quantity, its SI units can be derived from the standard values. We denote explicit numeric values in atomic units using the symbol $\SI{}{\au}$ (such as e.g. $p=\SI{0.5}{\au}$). The conversion to SI or other values then follows using the following equivalences.

\begin{table}[h]
\centering
\begin{tabular}{rccll}
Quantity & Unit & Scaling & Significance & Value in SI units
\\ \hline
mass     & $\displaystyle\vphantom{\sum} m_e$ & 1 & Electron mass&  $\SI{9.109e-31}{kg}\displaystyle\vphantom{\sum}$\\
action   & $\displaystyle\vphantom{\sum_a} \hbar \displaystyle\vphantom{\sum_a^b} $ & 1 &\pbox{20cm}{Reduced Planck \\[0mm]constant} &  \SI{1.054e-34}{J\,s}\\
charge   & $\displaystyle\vphantom{\sum} e\vphantom{\sum} $     & 1 & Electron charge & \SI{1.602e-19}{C}\\
length   & $\displaystyle\vphantom{\sum_a^b} a_0=\displaystyle \vphantom{\sum_a} \frac{\hbar^2}{m_e k_\mathrm{c} e^2}$ & $\displaystyle 1/\kappa$ & Bohr radius & \SI{5.291e-11}{m} \\
velocity & $\displaystyle\vphantom{\sum_a^b} \alpha c =  \frac{k_\mathrm{c}e^2}{\hbar}$ & $\displaystyle 1/\kappa$ &  Bohr velocity & $\SI{2.188e6}{m/s}$\\
time     & $\displaystyle\vphantom{\sum_a^b}  \frac{\hbar}{E_\mathsf{H}} =\frac{\hbar^3}{m_e k_\mathrm{c}^2 e^4}$ & $\displaystyle 1/\kappa^2$ & Bohr period & $\SI{2.419e-17}{s}$\\
momentum & $\displaystyle\vphantom{\sum_a^b}  \sqrt{m_eE_\mathsf{H}}=\frac{m_e k_\mathrm{c}e^2}{\hbar}$ & $\kappa$ &  \pbox{20cm}{Bohr\\[0mm]wavevector}  & $\SI{1.993e-24}{\kilo\gram\,\meter/s}$\\
energy   & $E_\mathsf{H} = \displaystyle\vphantom{\sum_a^b} \frac{m_e k_\mathrm{c}^2 e^4}{\hbar^2}$ & $\displaystyle \kappa^2$ & Hartree energy & \pbox{20cm}{$\SI{4.360e-18}{J}$\\$=\SI{27.21}{eV}$}\\
electric field
        & $\displaystyle\vphantom{\sum_a^b} \frac{E_\mathsf{H}/e}{a_0}=\frac{m_e^2 k_\mathrm{c}^3 e^5}{\hbar^4}$ & $\kappa^3$ & \pbox{20cm}{Proton field\\[0mm]at $1a_0$} & $\SI{5.142e11}{V/m}$ \\
intensity  & \hspace{4mm} $\displaystyle  \frac{\eps_0c}{2}\left(\frac{E_\mathsf{H}/e}{a_0}\right)^2  $ & $\kappa^6$  & \pbox{20cm}{Intensity at\\[0mm] $F=\SI{1}{\au}$} &  $\SI{3.509e16}{W/cm^2}$ \\
\hline
\end{tabular}
\captionsetup{width=\textwidth}
\caption{Conversion factors between atomic units and the SI system, with the latter arbitrarily truncated to four significant figures.}
\end{table}

Two specific conversion factors, in particular, are useful to point out:
\begin{equation}
\omega =\frac{\SI{45.6}{nm}}{\lambda} \, \SI{}{\au}
\quad \text{and} \quad
F = \sqrt{\frac{I}{\SI{e14}{W/cm^2}}} \, \SI{0.053}{\au}
,
\end{equation}
giving the translation between the wavelength $\lambda$ of a light beam and its angular frequency $\omega$ in atomic units, and similarly between the intensity $I$ of a monochromatic, linearly polarized beam in $\SI{}{W/cm^2}$ and the peak electric field strength $F$ in atomic units. The numbers in this factors are easily obtained via
\begin{equation}
\frac{2\pi a_0}{\alpha}\approx \SI{45.6}{nm}
\quad \text{and} \quad
\sqrt{\frac{\SI{e14}{W/cm^2}}{\SI{3.509e16}{W/cm^2}}} \approx 0.053
,
\end{equation}
where in the former $\alpha$ is the speed of light in atomic units, so $a_0/\alpha$ is the frequency of light of wavelength $\SI{1}{\au}$.

In addition to the explicit numbers, we retain a specific scaling column, which indicates how the quantities vary with the ionization potential of the system. This is useful because much of strong-field physics, from the SFA onwards, deals with essentially a single-electron problem (so $\hbar=m_e=e=k_c=1$ makes sense), which is nevertheless subjected to some given potential well with a fixed and unknown ionization potential $I_p$. In terms of equations, atomic units help simplify the hamiltonian of an $N$-electron atom,
\begin{subequations}
\begin{equation}
\hat H
=
-\sum_{i=1}^N \frac{\hbar^2}{2m_e}\nabla_i^2
-\frac{Z e^2}{4\pi\eps_0} \sum_{i=1}^N \frac{1}{\|\vbr_i\|}
+\frac{e^2}{4\pi\eps_0} \sum_{i\neq j=1}^N \frac{1}{\|\vbr_i - \vbr_j\|}
\end{equation}
to an essentially dimensionless version,
\begin{equation}
\hat H
=
-\sum_{i=1}^N \frac{1}{2}\nabla_i^2
-\sum_{i=1}^N \frac{Z}{\|\vbr_i\|}
+\sum_{i\neq j=1}^N \frac{1}{\|\vbr_i - \vbr_j\|}
,
\end{equation}
\end{subequations}
but there is still an additional parameter, the nuclear charge, which determines the behaviour of the system, including its ionization potential.

Since strong-field physics mostly cares about what happens far from the nucleus, though, we can essentially reduce the effect of the atomic hamiltonian to just the ground state energy, $I_p$, but this will also re-scale most of the relevant quantities: the characteristic momentum and wavevector will scale with $\kappa=\sqrt{2I_p}$, the characteristic length of the ground state will vary as $1/\kappa$, and electric fields will change with $\kappa^3$. Since all dimensional analysis is essentially a scaling argument in disguise, the scalings with respect to $\kappa$ afford a way to do a limited amount of dimensional analysis even when working in atomic units.


\documentclass[11pt]{scrartcl} % Font size
\input{../structure.tex} % Include the file specifying the document structure and custom commands

%----------------------------------------------------------------------------------------
%	TITLE SECTION
%----------------------------------------------------------------------------------------

\title{
	\normalfont\normalsize
	\textsc{Harvard Privacy Tools Project}\\ % Your university, school and/or department name(s)
	\vspace{25pt} % Whitespace
	\rule{\linewidth}{0.5pt}\\ % Thin top horizontal rule
	\vspace{20pt} % Whitespace
	{\huge Median Sensitivity Proofs}\\ % The assignment title
	\vspace{12pt} % Whitespace
	\rule{\linewidth}{2pt}\\ % Thick bottom horizontal rule
	\vspace{12pt} % Whitespace
}

% \author{\LARGE} % Your name

\date{\normalsize\today} % Today's date (\today) or a custom date

\begin{document}

\maketitle

\begin{definition}
The sample median of a database $X = (x_1, \hdots, x_n)$ is given by
\[ f(X) = \frac{\tilde{x}_l + \tilde{x}_u}{2} \]
where $l = \lfloor \frac{n+1}{2} \rfloor$ and $u = \lceil \frac{n+1}{2} \rceil$ and
$\tilde{X} = (\tilde{x}_1, \hdots, \tilde{x}_n)$ is the sorted version of $X$.
\end{definition}

Note that this method of producing a DP median is not usable as the noise is scaled to the full range of the dataset.
\section{Neighboring Definition: Change One}

% l1 sensitivity
\subsection{$\ell_1$-sensitivity}
\begin{theorem}
	Let the database $X$ have elements bounded above by $M$ and below by $m$.
	Then the $\ell_1$-global sensitivity in the change-one model of the median is
	\[
		\Delta f(\cdot) =
			\begin{cases}
				\frac{M - m}{2}, \text{ if } n \equiv 0 \pmod{2} \\
				M-m \text{ if } n \equiv 1 \pmod{2}
			\end{cases}
	\]
\end{theorem}

\begin{proof}
	First consider the case where $n$ is such that $n \equiv 0 \pmod{2}$. Then our worst-case scenario is that exactly half of the data elements in $X$ are $m$ and the other half are $M$. In this case,
	$f(X) = \frac{m + M}{2}$. \newline

	Now consider an $X'$ which is identical to $X$ but with one additional element with value $M$.\footnote{The result holds if it is switched from $M$ to $m$.}
	Then we have that $f(X') = M$. Because we are looking at our worst-case pairing of $X,X'$,
	we know that
	\[ \Delta f(\cdot) = \max_{X,X'} |f(X') - f(X)| = \big\vert M - \frac{m+M}{2} \big\vert = \frac{M-m}{2}. \]

	Now consider the case where $n$ is such that $n \equiv 1 \pmod{2}$.
	Then our worst-case scenario is that $\frac{n-1}{2}$ of the elements of $X$ are $m$,
	$\frac{n-1}{2}$ of the elements of $X$ are $M$, and the remaining element of $X$ is $m$ (WLOG).
	In this setting, $f(X) = m$.
	Let $X'$ be identical to $x$ but with one element switched from $m$ to $M$.
	Then $f(X') = M$ and we have that
	\[ \Delta f(\cdot) = \max_{X,X'} |f(X') - f(X)| = |M - m|. \]
\end{proof}

% l2 sensitivity
\subsection{$\ell_2$-sensitivity}
\begin{theorem}
	Let the database $X$ have elements bounded above by $M$ and below by $m$.
	Then the global $\ell_2$-sensitivity in the change-one model of the median is
	\[
		\Delta f(\cdot) =
			\begin{cases}
				\frac{M - m}{2}, \text{ if } n \equiv 0 \pmod{2} \\
				M-m \text{ if } n \equiv 1 \pmod{2}
			\end{cases}
	\]
\end{theorem}

\begin{proof}
	The logic follows exactly from the proof of the $\ell_1$ sensitivity,
	just with the norm in the last line of each statement switched from 1 to 2.
\end{proof}

\section{Neighboring Definition: Add/Drop One}

% l1 sensitivity
\subsection{$\ell_1$-sensitivity}

\begin{theorem}
Let the database $X$ have elements bounded above by $M$ and below by $m$. Then the global $\ell_1$-sensitivity in the add/drop-one model of the median is
$$ \Delta f(\cdot) = \frac{M-m}{2}.$$
\end{theorem}

\begin{proof}

First consider the case where $n$ is such that $n \equiv 0 \pmod{2}$. Then our worst-case scenario is that exactly half of the data elements in $X$ are $m$ and the other half are $M$. In this case, $f(X) = \frac{m + M}{2}$. \\

Now consider an $X'$ which is identical to $X$ but with a single additional element $M$.Then $f(X') = M$. Note that if instead $X'$ was identical to $X$ with a single element \textit{removed}, the worst case is that a single $m$ is removed and again $f(X') = M$.\footnote{The results holds if the point added/removed is switched from $M$ to $m$.}  In either case,
$$ \left\vert f(X') - f(X) \right\vert = \left\vert M - \frac{M-m}{2} \right\vert = \frac{M-m}{2}.$$

Now consider the case where $n$ is such that $n \equiv 1 \pmod{2}$.
Then our worst-case scenario is that $\frac{n-1}{2}$ of the elements of $X$ are $m$, and $\frac{n+1}{2}$ of the elements of $X$ are $M$ (WLOG). In this setting, $f(X) = M$. Let $X'$ be identical to $x$ but with one element $m$ added. Then $f(X') = \frac{M-m}{2}$. Note that if instead $X'$ was identical to $X$ with a single element removed, the worst case is that a single $M$ is removed and again $f(X') = \frac{M-m}{2}$ (WLOG). In either case,

$$ \left\vert f(X) - f(X') \right\vert = \left\vert M - \frac{M-m}{2} \right\vert = \frac{M-m}{2}.$$

So, in general,

$$ \Delta f(\cdot) = \max_{X,X'} \left\vert f(X') - f(X) \right\vert = \frac{M-m}{2}. $$
\end{proof}

% l2 sensitivity
\subsection{$\ell_2$-sensitivity}

\begin{theorem}
Let the database $X$ have elements bounded above by $M$ and below by $m$. Then the global $\ell_2$-sensitivity in the add/drop-one model of the median is
$$ \Delta f(\cdot) = \frac{M-m}{2}.$$
\end{theorem}

\begin{proof}
The logic follows exactly from the proof of the $\ell_1$ sensitivity, just with the norm switched from 1 to 2.

\end{proof}
\end{document}


\subsection{Analytical Model}
	%Is it clear that we're trying to demonstrate a model that can be experimentally validated that has geothermal gradient? Is it also clear that we're hoping to conduct CBHE configuration optimization? Is it clear that we also hope to simulate seasonal performance of the CBHE? (The last one is very, very unclear.
	We will be adapting the analytical model from Beier et al., which was developed to predict the thermal response from a CBHE with known geological parameters. This model was developed to adopt undisturbed ground temperature measurement from fiber optic temperature sensors (also referred to as distributed temperature sensor, or DTS).

	%Explain the method, and the ADAPTION~ using a different reference temperature profile, also re-wrote the code into Python to be used as a class for different configurations to have its performance estimated and validated(use a plot to show its performance comparison?).
	Typically, the overall thermal resistance of a geothermal bore can be considered as the combined resistance of the bore and the ground. The bore thermal resistance can be affected by many parameters, including the pipe material, configuration of the heat exchanger as well as the thermal conductivity of the grout/backfill in the bore annulus. The ground resistance is dependent primarily on the thermal conductivity and the diffusivity of the surrounding formation. For a vertical BHE, its thermal resistance is the combined effect of pipe resistance and bore annulus grout resistance. As Kavanaugh and Rafferty pointed out, the terms of pipe and grout resistance can be combined into a single Equation~\ref{eq:Rb}.

	\begin{equation}
		R_b = R_p + R_{grt} = R_{film} + R_{tube} + R_{grt} =
		\frac{1}{\pi d_i h_{conv}} \frac{ln(d_o/d_i)}{2\pi k_p} + \frac{ln(d_b/d_o)}{2\pi k_{grt}}\label{Rb}
	\end{equation}

	This equation translates the thermal resistance of the pipe to the combination of the pipe resistances and the fluid film resistance inside the pipe wall. For coaxial borehole heat exchanger, this translates to both the film resistance at the inner pipe and the borehole wall, as well as the tube thermal resistance of both the outer and inner pipes. Calculation of the tube thermal resistance is relatively straight forward as the values required includes the diameter of the tubes and the thermal conductivity of it. However, as we are more interested in varying the configuration and insulation level at the borehole as we are showing conceptually in the section of the CBHE, we need to expand the existing definition of the shunt resistance of the borehole heat exchanger. Building on the existing expressions from Kavanaugh and Rafferty (2014) as well as Beier et al. (2012), we have a new expression of the shunt resistance of the borehole $R_{12}$.

	%shunt resistance R12, refer to the borehole section plot. highlight geothermal gradient usage
	More specifically, the shunt resistance $R_p$, or sometimes referred to as $R_{12}$ of the CBHE is a parameter that we can modify to achieve different yield from a known location with certain geological condition.
	%Our primary goal is to achieve an easy-to-use solution that compares the heat extraction capability of different R12, Rg and Rs.
	%Config
	From the schematic diagram, it is evident that any design intervention to change the performance of a CBHE needs to happen at the level that affect the shunt resistance. This expression allows us to evaluate the thermal resistances of CBHEs, we group the contributing variables into two categories: direct and indirect. Direct variables are the diameters of the inner and outer pipes, thermal conductivity of the pipe material, and the thickness and material of the insulation material inside the inner pipe. The flow rate entering the CBHE is the indirect variable, which not only affect the convective heat transfer coefficients contributing to the film thermal resistances. To provide a more accurate description of the thermal resistance of the shunt resistance, expression of $R_{12}$ needs to be updated as Equation~\ref{eq:R12}. This includes the film thermal resistances at the heat exchanger surfaces, and the thermal resistances that represents the conductive heat transfer through the pipe and insulation materials, i.e. $R_{pw1}, R_{ins}, R_{pw2}$. More explicitply, these individual expressions can be written as Equation~\ref{eq:RR12}, where the overall shunt resistance may change with respect to different CBHE configurations. This is also expressed in Figure~\ref{fg:cbhesec}.

	    \begin{equation}
          R_{12} = R_{fi} + R_{pw1}+ R_{ins}+ R_{pw2} + R_{fo} \label{eq:R12}
        \end{equation}

        \begin{equation}
            Nu = \frac{hL}{k}\label{eq:Nuhx}
        \end{equation}
        \begin{equation}
              \left\{
              \begin{aligned}
              & R_{fi} = \frac{1}{\pi d_{pi} h_{pi}}\\
              & R_{pw1} = \frac{ln(\frac{d_{pw1}}{d_{pi}})}{2\pi k_{pw}}\\
              & R_{ins} = \frac{ln(\frac{d_{pw2}}{d_{pw1}})}{2\pi k_{ins}}\\
              & R_{pw2} = \frac{ln(\frac{d_{po}}{d_{pw2}})}{2\pi k_{pw}}\\
              & R_{fo} = \frac{1}{\pi d_{po} h_{po}}
              \end{aligned}
              \right. \label{eq:RR12}
        \end{equation}

		\begin{figure*}[h!]
			\centering
			\includegraphics[width=0.8\textwidth]{data/CBHE_CrossSection}
			\caption{Schematic diagram of thermal resistance calculation for borehole.}\label{fg:cbhesec}
		\end{figure*}
	%These are the parameters that we are primarily interested in varying when changing the R12

If we may overtly simplify the entangled the relationship between the depth, performance and cost can be generalised into a statement: the further down the reach of the borehole, the higher the bottom of borehole temperature, and the larger the drilling costs and operational (pumping costs). And to improve the heat exchanger capability of any CBHE, we will therefore need to either change the configuration of the CBHE, or the location of the CBHE. This can be categorized into either shunt-resistance-related parameters and the site-specific parameters.

%How the model works?

	\subsubsection{Diameter, insulation level, and flow rates}
	Diameters, insulation level and flow rates are parameters that we may subjectively alter to modify the performance of borehole heat exchangers.
	%insulation
	To better utilise the geothermal energy that is returned to the ground surface, insulating the inner pipe of CBHEs so that the heat transfer between the inner tube and annulus will not short-circuit the heat extraction in the CBHE.
	The resulting importance of adding insulation on the inner pipe was highlighted in a few previous publications \cite{li_synthesis_2014,guillaume_analysis_2011}but was found to be not economically feasible for project proposal\cite{dijkshoorn_measurements_2013}.
	One such study came from Dijkshoorn et al. , in which the construction and measurement of a 2500m deep well helped to validate the modelling of satisfying borehole performance over 30 years when using the borehole output to drive a climate control adsorption chiller. However, their results did not support the extra investment of adding an insulated inner pipe for the borehole - the entire project came to a halt at such.
	Additionally, despite acknowledging the possibility of added thermal benefit by inserting an insulated inner pipe, this was not further pursued due to cost constraints. In a very recent publication, the effect of changing the pipe configuration to achieve better thermal performances, but does not vary the design and environmental (specifically on the geothermal gradient) parameters component-by-component in CBHE design\cite{liu_numerical_2019}.

	%Depth
	\subsubsection{Geothermal gradient and thermal conductivity}
	Using the same set of method outlined by Beier et al. \cite{beier_situ_2012}, it is possible to use an arbitrary temperature profile as the the undisturbed ground temperature and solve for corresponding ground temperature.

	Another modification of the method we're adapting is described as Equation~\ref{eq:bcggradient}, where the temperature distribution along the depth of CBHE can be considered constant at locations that are infinitely far away from the center of the test well.

	\begin{equation}
            \frac{\partial T_{DS}}{\partial z_D}(r_D\rightarrow \infty, t_D,z_D) = g_D(z_D) \quad t_D > 0\label{eq:bcggradient}
    \end{equation}

	Geothermal gradient, thermal conductivity, are parameters that varies objectively, but varies significantly enough spatially that could also affect the performance of a CBHE. Addressing the presence of geothermal gradient is therefore extremely important when the proposed boreholes are deeper rather than shallower. Existing studies show that geothermal gradient may vary between 1 to 5 Kelvin per hundred meters' depth\cite{holmberg_thermal_2016,shrestha_assessment_2018}.

	%Validation of the analytical model

	%Comparison with the constant ground temperature solution

	%Thermal resistances. Look at the GTRI report also for a good reference.
\subsection{Analytical Solution}
	For each time step, a new analytical solution can be solved along different t, r and depth in CBHE. Following the same set of method

	%Python
	As we are interested in the possible benefits of designing CBHEs better through different combinations of configurations, we are primarily interested in creating a lightweight algorithm that allows us to compare the expected thermal response outcomes (particularly the thermal resistances or heat extracted) between the different configurations. We therefore adapted the analytical method from Beier et al. \cite{beier_borehole_2013} with the following modifications: expanded the shunt resistance expression to allow for extra thermal insulation inside the inner pipe; adopted geothermal gradient into the undisturbed ground temperature during the solving of the target temperature function and translated the original analytical model from MathCAD into Python as a class that allows parallel comparison of the resulting thermal resistance of the boreholes.

	Therefore, for every time step during a simulated hypothetical time step, the corresponding analytical solution can be calculated for a given radius, depth and time since operation. Using Laplace transformation, the heat exchange within the central and annular flow can be solved using the Navier-Stokes equation with boundary and initial conditions. As all the variables were converted into dimensionless form, including the time component, the analytical solution requires an inverse Laplace transform to calculate temperatures in the time domain. The detailed solution of the energy equations using the initial and boundary conditions can be found in the appendix for the annulus as inlet scenario. We used the Stehfast algorithm following Beier's example in his 2013 paper\cite{beier2013} to perform the inverse laplace transformation.

\subsection{Validation of adapted model}
	To confirm the validity of our adapted model, we want to compare the temperature profile that we can create by modeling the temperature distribution inside the CBHE. The parameter we used as the model input are as the followings shown in Table~\ref{tb:inputs_val}.

	\begin{table}[h!]
            \begin{center}
            % \small\addtolength{\tabcolsep=0.11cm}{-5pt}
            % \scalbox{0.7}{
            \tabcolsep=0.11cm
%            {\singlespacing}
            \begin{tabular}{lcl}
                \hline
                Parameter & Symbol & Value\\
                \hline
                Borehole radius & $r_{b}$ & 115 mm\\
                Active heat exchanger length & L & 170 m\\
                Inner pipe outer radius & $r_{po}$ & 40 mm\\
%                Inner pipe wall thickness & $r_{po}$-$r_{pi}$ & 2.4 mm\\
                External pipe outer radius & $r_{eo}$ & 114 mm\\
                Inner pipe thickness & $d_{pp}$ & 2.4 mm\\
                External pipe thickness & $d_{ep}$ & 0.4 mm\\
                Inner and external pipe wall thermal conductivity & $k_{pp}$,$k_{ep}$ & 0.40 W/(K$\cdot$m)\\
                Ground thermal conductivity & $k_{s}$ & 3.15 W/(K$\cdot$m)\\
                Ground volumetric heat capacity & $c_{s}$ & 2.24 $\times$ $10^6$ J/(K$\cdot$$m^3$)\\
                Water flow rate & w & 0.58 $\times 10^{-3}m^3/s$\\
                Water density (at 15$^{\circ}$C) & $\rho$ & 999 kg/$m^3$\\
                Water volumetric heat capacity (at 15$^{\circ}$C) & $c_{w}$ & 4.19 $\times$ $10^6$ J/(K$\cdot$$m^3$)\\
                Water thermal conductivity (at 15$^{\circ}$C) & $k_{w}$ & 0.59 W/(K$\cdot$m)\\
                Water dynamic viscosity (at 15$^{\circ}$C) & $\mu_{w}$ & 1.138 $\times$ $10^{-3}$ kg/(m$\cdot$s)\\
%                Water Prandtl number & Pr & 8.09 \\
%                Heat input rate & Q & 6360 $W$\\
                Reference soil surface temperature & $T_{rs}$ & 8.9$^\circ$C\\
                % Average ground temperature & $T_{s}$ & 8.4$^\circ$C\\
                Nondimensional temperature of soil & $T_{DS}$ &\\
                Nondimensional temperature of inlet/outlet & $T_{D1},T_{D2}$ &\\
                \hline
            \end{tabular}
            \end{center}
            \caption{\label{table 2}Nomenclature, input parameters used in determining the performance of CBHE.}\label{tb:inputs_val}
	\end{table}


\section{Population Inference} \label{sec:hyper}
% restatement/high level explanation of what we do
We quantify the accuracy and precision of the inferred galaxy properties from
our SED modeling using population hyperparameters
$\eta_{\Delta} = \{\mu_{\Delta_\theta}, \sigma_{\Delta_\theta}\}$
(Section~\ref{sec:results}).
These hyperparameters describe the distribution of the difference between the
inferred and true parameters, $\Delta_{\theta}$, assuming that the distribution
has a Gaussian functional form (Eq.~\ref{eq:eta_gauss}).
The $\eta_\Delta$ values we present in this work are MAP estimates of
$p(\eta_\Delta | \{ X_i \})$, the probability distribution of $\eta_\Delta$
given some galaxy population observations.
They are inferred using population inference as described in the main text and
Eqs~\ref{eq:popinf} - \ref{eq:popinf2}.
Our approach for quantifying the accuracy and precision has a number of key
advantages over other methods.
For instance, a naive way to quantify the accuracy and precision would be to
estimate the median and standard deviations of individual posteriors then
averaging them.
This assumes that each individual posterior is close to a Gaussian.
As we later demonstrate, this is an incorrect assumption that reduces the
posterior distribution to point estimates.
Another approach would be to stack the posteriors by summing up all of the
individual posteriors.
Neither of these approaches mathematically estimate the distribution we are
actually interested in estimating: $p(\eta_\Delta | \{ X_i \})$.
Moreover, both approaches are biased.
\cite{malz2020} recently demonstrated this in the context of combining
photometric redshift posteriors.

\begin{figure}
\begin{center}
\includegraphics[width=0.45\textwidth]{figs/etas_demo.pdf}
    \caption{
    The $\log M_*$ distribution described by the accuracy and precision
    hyperparameters for galaxies with $10.6 < \log M_* < 10.8$:
    $\mathcal{N}(10.7 + \mu_{\Delta_\theta}, \sigma_{\Delta_\theta})$
    (black dashed).
    The hyperparameters are MAP estimates of $p( \mu_{\Delta_\theta},
    \sigma_{\Delta_\theta} | \{ X_i \})$ derived from population inference
    (Eq.~\ref{eq:popinf}-\ref{eq:popinf2}).
    We include individual $\log M_*$ posteriors of several galaxies with $M_*
    \sim 10^{10.7} M_\odot$ for comparison.
    The individual posteriors have a wide variety of shapes, which can bias
    naive estimates of their accuracy and precision.
    The comparison illustrates that
    $\mathcal{N}(\mu_{\Delta_\theta}, \sigma_{\Delta_\theta})$ provides a
    robust estimate of the overall accuracy and precision of the inferred
    posteriors.
    }\label{fig:eta_demo}
\end{center}
\end{figure}
We illustrate the population inference approach in Figure~\ref{fig:eta_demo}
where we present the distribution of $\log M_*$ described by the accuracy and
precision hyperparameters derived for galaxies with $10.6 < \log M_* < 10.8$:
$\mathcal{N}(\mu_{\Delta_\theta} + 10.7, \sigma_{\Delta_\theta})$ (black
dashed).
For comparison, we plot posteriors of $\log M_*$ for several individual
galaxies with $\log M_* \sim 10.7$.
There is significant variation in the individual posteriors and many of them
are not well described by a Gaussian distribution.
This variation is an expected consequence of noise in the observables and
MCMC sampling.
We note that estimating the accuracy and precision by stacking the posteriors,
for instance, significantly underestimates the precision.
Meanwhile, the accuracy and precision hyperparameters capture the overall
accuracy and precision of the individual posteriors.


\section{Model Functions}
The mathematical description of gravity effects are implemented in gravityEffector.cpp. This code performs the following primary functions
\begin{itemize}
	\item \textbf{GravBody Creation}: The code creates gravity bodies which are capable of affecting spacecraft. It does not effect a spacecraft unless that spacecraft explicitly adds the body as a gravity effector.
	\item \textbf{Orbital Energy}: The code can calculate the total orbital energy as well as orbital kinetic and orbital potential energy of a spacecraft about a gravity body.
	\item \textbf{Simple Gravity}: The code can compute a gravity acceleration between two bodies according to Newton's law of universal gravitation given $\mu$ and the distance between the bodies.
	\item \textbf{Spherical Harmonics}: The code can compute gravity acceleration between two bodies using the more-complex method of spherical harmonics. To do this, it must be provided with the same inputs as for calculating simple gravity. In addition, it needs to be provided a "degree" of spherical harmonics to be used and spherical harmonics coefficients useful up to that degree.
	\item \textbf{Multiple Body Effects}: The code can stack the effects of multiple gravity bodies on top of each other to determine the net effect on a spacecraft. The user must indicate in the spacecraft set-up which gravitational bodies should be taken into account.
	\item \textbf{Interface: Spacecraft States}: The code sends and receives spacecraft state information via the DynParamManager.
	\item \textbf{Interface: Energy Contributions}: The code sends spacecraft energy contributions via \\updateEnergyContributions() which is called by the spacecraft.
	\item \textbf{Interface: GravBody States}: The code outputs GravBody states(ephemeris information) via the Basilisk messaging system.

\end{itemize}

\section{Model Assumptions and Limitations}
The limitations of spherical harmonics gravity model are well-known and clearly explained in Schaub and Junkins' book\cite{schaub2014}. The limitations include:
\begin{itemize}
	\item \textbf{Coefficient Accuracy}: The coefficients used in the spherical harmonics equations are typically calculated based on gravitational data gathered by satellites. Therefore, the accuracy of the model is determined by the accuracy of the satellite instrumentation and precision of the stored data. Furthermore, for some bodies, there may not be sufficient information available to provide accurate coefficients or higher-degree coefficients.
	\item \textbf{Maximum Degree}: The spherical harmonics equation is a series expansion. Therefore, any implementation must truncate the equation at some point. The truncated portion of the equation necessarily defines some amount of error in the final calculation. This error is, however, small after the first handful of terms. Additionally, a larger distance between gravity body and spacecraft requires fewer terms of the series to achieve equal accuracy as compared to a case with less distance. This code allows the user to request a maximum number of terms to evaluate rather than a specific accuracy. This could lead to less-than-desirable accuracy with small separation distances and greater-than-necessary run times with large separation distances.
	\item \textbf{Planetary Ephemeris Data}: This code generally relies on an external package for planetary ephemeris information. Errors included in this package will translate into error in the gravity calculations, but those errors should be small. Because the ephemeris data is tabulated, this code should not be used to try to project the orbits of the celestial bodies in question. This could be done, though, by treating any celestial body as a "spacecraft".
\end{itemize}