\documentclass{article}
\usepackage{amsmath}
\begin{document}
\title{Fast discrete arctangent computation}
\author{Vyacheslav Chigrin}
\maketitle

\section{Introducion}
Discrete arctangent in that article is a two argument function $\mathcal{F}(x, y)$ parametrized by
integral parameter N. Current library supports only $N = 8k, k \in Z, N > 8$.
It returns zero-based "sector number" in which lies beam from coordinate origin to
point (x, y). Sectors are counted from 0 to N-1 counter clock-wise,
first sector contains beams for angles  [0, $\frac{2\pi}{N}$).

More formally speaking, assume $\alpha$ is an angle between $x$ axis and
point $(x, y)$ value of $\mathcal{F}(x, y) \in Z$ so that
\begin{equation}
\label{eq:F_def}
\mathcal{F}(x, y)\frac{2\pi}{N} \leq \alpha < (\mathcal{F}(x, y) + 1)\frac{2\pi}{N}
\end{equation}
or, equivalently
$$
\label{eq:F_def_floor}
\mathcal{F}(x, y) = \lfloor N \frac{\alpha}{2\pi} \rfloor
$$
In this document we'll use either two-argument form $\mathcal{F}(x, y)$ when
calclating arcatngent for point $(x, y)$ or single argument form
$\mathcal{F}(\alpha)$ for simplicity - here $\alpha$ is an angle between $x$ axis
and $(x,y)$ point, as written above.

\section{Math background}
\subsection{Reduction problem to angles only in $[0, \frac{\pi}{4})$}

If $\alpha \ge \pi$ then we can compute
\begin{equation}
\mathcal{F}(\alpha - \pi) =
\lfloor \frac{(\alpha - \pi)N}{2\pi} \rfloor =
\lfloor \frac{\alpha N}{2\pi} - \frac{N}{2} \rfloor =
\lfloor \frac{\alpha N}{2\pi} \rfloor - \frac{N}{2} =
\mathcal{F}(\alpha) - \frac{N}{2}
\end{equation}
Here last expression is valid since $\frac{N}{2} \in Z$ by definition of
$N$ suported by the library. Re-ordering last inequality gives us
\begin{equation}
\label{eq:F_mirror_1}
\mathcal{F}(\alpha) = \mathcal{F}(\alpha - \pi) + \frac{N}{2}
\end{equation}
Calculating point $(x', y')$ for angle $\alpha - \pi$ from point $(x, y)$ is
straighforward. We can re-write original point coords as
\begin{equation}
x = R\cos(\alpha); y = R\sin(\alpha)
\end{equation}
where $R$ is a distance from coordinate origin to point $(x, y)$. So
\begin{multline}
\label{eq:F_mirror_1_coords}
x' = R\cos(\alpha - \pi) = R(\cos(\alpha)\cos(\pi) + \sin(\alpha)\sin(\pi)) =
-R\cos(\alpha) = -x \\
y' = R\sin(\alpha - \pi) = R(\sin(\alpha)\cos(\pi) - \cos(\alpha)\sin(\pi)) =
-R\sin(\alpha) = -y
\end{multline}

If $\pi > \alpha \ge \frac{\pi}{2}$ then same as in \eqref{eq:F_mirror_1} we get
\begin{equation}
\label{eq:F_mirror_2}
\mathcal{F}(\alpha) = \mathcal{F}(\alpha - \frac{\pi}{2}) + \frac{N}{4}
\end{equation}
And new coords $(x', y')$
\begin{multline}
\label{eq:F_mirror_2_coords}
x' = R\cos(\alpha - \frac{\pi}{2}) = R(\cos(\alpha)\cos(\frac{\pi}{2}) + \sin(\alpha)\sin(\frac{\pi}{2})) =
R\sin(\alpha) = y \\
y' = R\sin(\alpha - \frac{\pi}{2}) = R(\sin(\alpha)\cos(\frac{\pi}{2}) - \cos(\alpha)\sin(\frac{\pi}{2})) =
-R\cos(\alpha) = -x
\end{multline}

And finally if $\frac{\pi}{2} > \alpha \ge \frac{\pi}{4}$ then same as in \eqref{eq:F_mirror_1} we get
\begin{equation}
\label{eq:F_mirror_3}
\mathcal{F}(\alpha) = \mathcal{F}(\alpha - \frac{\pi}{4}) + \frac{N}{8}
\end{equation}
And new coords $(x', y')$
\begin{multline}
x' = R\cos(\alpha - \frac{\pi}{4}) = R(\cos(\alpha)\cos(\frac{\pi}{4}) + \sin(\alpha)\sin(\frac{\pi}{4})) =
R\frac{\sqrt{2}}{2}(\cos(\alpha) + \sin(\alpha)) = \frac{\sqrt{2}}{2}(x + y)\\
y' = R\sin(\alpha - \frac{\pi}{4}) = R(\sin(\alpha)\cos(\frac{\pi}{4}) - \cos(\alpha)\sin(\frac{\pi}{4})) =
R\frac{\sqrt{2}}{2}(\sin(\alpha) - \cos(\alpha)) = \frac{\sqrt{2}}{2}(y - x)
\end{multline}
Since multiplying both coords to the same scalar does not change angle $\alpha$ we're interested in, we
can use in our calculations.
\begin{multline}
\label{eq:F_mirror_3_coords}
x' = (x + y) \\
y' = (y - x) \\
\end{multline}

\subsection{Computing function for angles in $[0, \frac{\pi}{4})$}
Assume $f = \mathcal{F}(\alpha)$ for $\alpha \in [0, \frac{\pi}{4})$.
On that interval range for f, assuming N is multiple by 8.
\begin{equation}
\label{eq:f_range}
0 \leq f < \frac{N}{8}
\end{equation}
Or, since $f \in Z$
\begin{equation}
\label{eq:f_range_2}
0 \leq f \leq \frac{N}{8} - 1
\end{equation}

Since $\tan$ function monotonically increases on that interval we can write
\begin{equation}
\label{eq:f_def_2}
\tan(f\frac{2\pi}{N}) \leq \tan(\alpha) < \tan((f + 1)\frac{2\pi}{N})
\end{equation}

Let's introduce table T:
\begin{equation}
\label{eq:T_def}
T[k] = \tan(\frac{2\pi k}{N}), k \in Z, k \in [0, \frac{N}{8}]
\end{equation}
Note that $T[k+1] > T[k] \forall  k$ since $\tan$ is monotonically increasing.

\begin{equation}
\label{eq:T_alpha_ineq}
T[f] \le \tan(\alpha) < T[f + 1]
\end{equation}
and our task is quickly find elemend $f$, satisfying this inequality.

Assume we can build index table $J$ of size $S$, so that
\begin{equation}
\label{eq:J_def}
T[J[k] - 1] < \frac{k}{S} \leq T[J[k]],
J[k] \geq 0 \forall k
\end{equation}
We can satisfy this inequality only if $S > Smin$.
This inequality becomes possible when $\frac{1}{S} < \min_{i}(T[i + 1] - T[i])$.
That is evident - since values $\frac{k}{S}$ placed uniformly, in that
case between any $T[i]$ and $T[i + 1]$ will be at least one $\frac{k}{S}$ value.
So
\begin{multline}
\frac{1}{S} < \min_{i}(\tan(\frac{2\pi (i + 1)}{N}) - \tan(\frac{2\pi i}{N})) \\
 =  \min_{i}(\frac{\sin(\frac{2\pi (i + 1)}{N} - \frac{2\pi i}{N})}{\cos(\frac{2\pi (i + 1)}{N})\cos(\frac{2\pi i}{N})})
 =  \min_{i}(\frac{\sin(\frac{2\pi}{N})}{\cos(\frac{2\pi (i + 1)}{N})\cos(\frac{2\pi i}{N})})
\end{multline}
Since $\cos$ funcion is monotonically decreasing on $[0, \frac{\pi}{2})$, maximum value in
denominator achieved when $i = 0$. So we get
\begin{equation}
\label{eq:Smin_value}
\frac{1}{S} < \frac{\sin(\frac{2\pi}{N})}{\cos(\frac{2\pi}{N})} = \tan(\frac{2\pi}{N}),
S > Smin = \frac{1}{\tan(\frac{2\pi}{N})}
\end{equation}

Having table $J$ we can quickly find values of $f$ with it we can prove that
\begin{equation}
\label{eq:J_ineq_prove}
T[J[\lfloor \tan(\alpha) S \rfloor - 1]] \leq T[f] \leq T[J[\lfloor \tan(\alpha) S \rfloor]]
\end{equation}
in that case we need make only one comparison after computing $\tan(\alpha) = \frac{y}{x}$.

First prove left part of \eqref{eq:J_ineq_prove}. From \eqref{eq:J_def} we get
\begin{equation}
T[J[\lfloor \tan(\alpha) S \rfloor - 1]] < \frac{\lfloor \tan(\alpha) S \rfloor}{S} \leq \frac{\tan(\alpha)S}{S} = \tan\alpha
\end{equation}
From this and from \eqref{eq:T_alpha_ineq} we get
\begin{equation}
\label{eq:P1}
T[J[\lfloor \tan(\alpha) S \rfloor - 1]] < T[f + 1]
\end{equation}
Because values in T monotonically increase, and $f \in Z$ from \eqref{eq:P1} we have
\begin{equation}
T[J[\lfloor \tan(\alpha) S \rfloor - 1]] \leq T[f]
\end{equation}
that is the left part of \eqref{eq:J_ineq_prove}, Q.E.D.

Proof of the right part of \eqref{eq:J_ineq_prove}. Assume that it is wrong, that is
\begin{equation}
\label{eq:Wrong_inequality}
T[f] > T[J[\lfloor \tan(\alpha) S \rfloor]]
\end{equation}
From \eqref{eq:T_def} and \eqref{eq:F_def_floor}
\begin{multline}
T[f] = \tan(\frac{2\pi f}{N}) = \tan(\frac{2\pi \lfloor N \frac{\alpha}{2 \pi} \rfloor}{N}) \\
\tan(\frac{2\pi \lfloor N \frac{\alpha}{2 \pi} \rfloor}{N}) <  \tan(\frac{2\pi (\frac{N \alpha}{2 \pi} - 1)}{N}) =
\tan(\alpha - \frac{2\pi}{N})
\end{multline}
Substititute this and \eqref{eq:J_def} to \eqref{eq:Wrong_inequality} and get
\begin{multline}
\tan(\alpha - \frac{2\pi}{N}) > T[f] > T[J[\lfloor \tan(\alpha) S \rfloor]] \ge \frac{\lfloor \tan(\alpha) S \rfloor}{S} \\
\tan(\alpha - \frac{2\pi}{N}) > \frac{\lfloor \tan(\alpha) S \rfloor}{S} > \frac{\tan(\alpha) S - 1}{S} = \tan(\alpha) - \frac{1}{S} \\
\frac{1}{S} > \tan(\alpha) - \tan(\alpha - \frac{2\pi}{N}) = \frac{\sin(\frac{2\pi}{N})}{\cos(\alpha)\cos(\frac{2\pi}{N})} = \\
  \tan(\frac{2\pi}{N}) \frac{1}{\cos(\alpha)} \ge \tan(\frac{2\pi}{N})
\end{multline}
But before in \eqref{eq:Smin_value} we took $\frac{1}{S} < \tan(\frac{2\pi}{N})$. We get to contradiction,
so right part of \eqref{eq:J_ineq_prove} is proven $\forall S > Smin$.

\section{Algorighm}
\begin{enumerate}
\item Build table T as described in \eqref{eq:T_def}.
\item Take $S = \lceil \frac{1}{\tan(\frac{2\pi}{N})} \rceil$.
\item Build table J as described in \eqref{eq:J_def}.
\item For each input point:
\begin{enumerate}
\item For input point $(x, y)$ get corresponding point $(x', y')$, arctangent of
      which lies in $[0, \frac{\pi}{4})$. Also compute required offset for result.
      Use for that consequently equations
      \eqref{eq:F_mirror_1}, \eqref{eq:F_mirror_1_coords},
      \eqref{eq:F_mirror_2}, \eqref{eq:F_mirror_2_coords},
      \eqref{eq:F_mirror_3}, \eqref{eq:F_mirror_3_coords}.
\item Calculate $\tan(\alpha) = \frac{x'}{y'}.$
\item Make initial guess $r = J[\lfloor \tan(\alpha)S \rfloor] - 1$. From
    \eqref{eq:J_ineq_prove} we know that either $f = r$ or $f = r + 1$.
\item Compare $\tan(\alpha)$ with $T[r + 1]$. Accorgind to \eqref{eq:T_alpha_ineq}
    must be $\tan(\alpha) < T[f + 1]$ if this inequality does not hold for $f = r$, we
    must use $f = r + 1$.
\item Get final function result $\mathcal{F}(x, y)$ having computed value of
$f$ for $(x', y')$ and offset for it.
\end{enumerate}
\end{enumerate}
For sake of better CPU cache usage we can put both value of $J[r]$ and $T[r + 1]$
in the same table item.

\end{document}


\section{System of Particles}
We have considered the motion of a single particle in a force field, so we will now turn to a system of particles where they act on each other.\\
Consider $N$ particles, namely particles $1,\ldots,i,\ldots,N$ having masses $m_i$ and positions $\underline{r_i}(t)$.
The momentums are then $\underline{p_i}=m_i\underline{\dot{r}_i}$.
Newton's Second Law for one of these particles is then $m_i\underline{\ddot{r}_i}=\underline{\dot{p}_i}=\underline{F_i}$.
Divide the forces exerted in two parts: the external forces $\underline{F_i}^{\rm ext}$ (causes by something outside the $N$ particles) and internal forces $\underline{F_{ij}}$ which is the force exerted by particle $j$ on $i$.
Conventionally we take $\underline{F_{ii}}=\underline{0}$.
So basically
$$\underline{F_i}=\underline{F_i}^{\rm ext}+\sum_j\underline{F_{ij}}$$
Newton's Third Law then tells us $\underline{F_{ij}}+\underline{F_{ji}}=0$, like gravitation.
\subsection{Motion of the Centre of Mass}
The total mass of the system is $M=\sum_im_i$, then we define the centre of mass to be a location
$$\underline{R}=\frac{1}{N}\sum_{i=1}^Nm_i\underline{r_i}$$
The total linear momentum would be $\underline{P}=\sum_i\underline{p_i}=\sum_im_i\underline{\dot{r}}=M\underline{\dot{R}}$.
Consider the rate of change of the momentum.
By Newton's Secon Law,
$$\underline{\dot{P}}=M\underline{\dot{R}}=\sum_{i=1}^N\underline{\dot{p}_i}=\sum_{i=1}^N\underline{F_i}^{\rm ext}+\sum_{i=1}^N\sum_{j=1}^N\underline{F_{ij}}=\sum_{i=1}^N\underline{F_i}^{\rm ext}=\underline{F}^{\rm ext}$$
By $\underline{F_{ij}}=-\underline{F_{ji}}$.
So the motions of the centre of mass closely resembles that of a single particle with mass $M$ and position $\underline{R}$, which is reassuring since it means we can consider finite (bounded) bodies as particles.
So Newton's Second Law applies to macroscopic objects.
A simple conclusion from this is if $\underline{F}^{\rm ext}=0$, then the total momentum of the system $\underline{\dot{P}_i}=\sum_{i=1}^N\underline{\dot{p}_i}$ is conserved.
So in this case, we can set up the inertial frame as the centre of mass frame, in which $\underline{\dot{R}}=\underline{0}$.\\
Now we turn to consider the angular momentum.
Consider the total angular momentum about the origin, which is $\underline{L}=\sum_i\underline{r_i}\times\underline{p_i}$, then
\begin{align*}
    \underline{\dot{L}}&=\sum_{i=1}^N\underline{r_i}\times\underline{\dot{p}_i}+\sum_{i=1}^N\underline{\dot{r}_i}\times\underline{p_i}\\
    &=\sum_{i=1}^N\underline{r_i}\times\underline{\dot{p}_i}\\
    &=\sum_{i=1}^N\underline{r_i}\times\underline{F_i}^{\rm ext}+\sum_{i=1}^N\sum_{j=1}^N\underline{r_i}\times\underline{F_{ij}}\\
    &=\underline{G}^{\rm ext}+\frac{1}{2}\sum_{i=1}^N\sum_{j=1}^N(\underline{r_i}-\underline{r_j})\times\underline{F_{ij}}
\end{align*}
The last term is sometimes zero, in which case the rate of change would be $\underline{G}^{\rm ext}$, the total external torque.
\subsection{Motion relative to the Centre of Mass}
Write $\underline{r_i}=\underline{R}+\underline{s_i}$, so $\underline{s_i}$ is the position of particle $i$ relative to the centre of mass.
Then
$$\sum_{i=1}^Nm_i\underline{s_i}=\sum_{i=1}^Nm_i(\underline{r_1}-\underline{R})=\sum_{i=1}^Nm_i\underline{r_i}-M\underline{R}=0$$
Consequently $\sum_im_i\underline{\dot{s}_i}=0$.
As for the total linear momentum, since we have the above,
$$\underline{P}=\sum_{i=1}^Nm_i(\underline{\dot{R}}+\underline{\dot{s}_i})=M\underline{\dot{R}}$$
The angular momentum would have, exploiting the same fact,
\begin{align*}
    \underline{L}&=\sum_{i=1}^Nm_i(\underline{R}+\underline{s_i})\times(\underline{\dot{R}}+\underline{\dot{s}_i})\\
    &=\sum_{i=1}^Nm_i\underline{R}\times\underline{\dot{R}}+\sum_{i=1}^Nm_i\underline{s_i}\times\underline{\dot{s}_i}+\left( \sum_{i=1}^Nm_i\underline{s_i} \right)\times\underline{\dot{R}}+\underline{R}\times\left( \sum_{i=1}^Nm_i\underline{\dot{s}_i} \right)\\
    &=\sum_{i=1}^Nm_i\underline{R}\times\underline{\dot{R}}+\sum_{i=1}^Nm_i\underline{s_i}\times\underline{\dot{s}_i}\\
    &=M\underline{R}\times\underline{\dot{R}}+\sum_{i=1}^Nm_i\underline{s_i}\times\underline{\dot{s}_i}
\end{align*}
which is the angular momentum of the centre of mass plus the total angular momentum relative to the centre of mass.
The total kinetic energy is
\begin{align*}
    T&=\sum_{i=1}^N\frac{1}{2}m_i|\underline{\dot{r}_i}|^2\\
    &=\sum_{i=1}^N\frac{1}{2}m_i|\underline{\dot{R}}+\underline{\dot{s}_i}|^2\\
    &=\sum_{i=1}^N\frac{1}{2}m_i|\underline{\dot{R}}|^2+\sum_{i=1}^N\frac{1}{2}m_i|\underline{\dot{s}_i}|^2+\underline{\dot{R}}\cdot\left(\sum_{i=1}^Nm_i\underline{\dot{s}_i}\right)\\
    &=\frac{1}{2}M|\underline{\dot{R}}|^2+\frac{1}{2}\sum_{i=1}^Nm_i|\underline{\dot{s}_i}|^2
\end{align*}
Now is the energy conserved?
Assuming $\underline{F}^{\rm ext}$ is conserved, then $\underline{F}^{\rm ext}=-\nabla V^{\rm ext}$.
Take $\underline{F_{ij}}$ to be conserved as well and its potential purely depends on the seperation between the particles, then $\underline{F_{ij}}=-\nabla V_{ij}(\underline{r_i}-\underline{r_j})$.
We can show that the total energy is conserved under these assuming these by just differentiating.
\subsection{The Two Body Problem}
The centre of mass is $\underline{R}=(m_1\underline{r_1}+m_2\underline{r_2})/M$
Consider the seperation vector $\underline{r}=\underline{r_1}-\underline{r_2}$, so we can write
$$\begin{cases}
    \underline{r_1}=\underline{R}+\frac{m_2}{m}\underline{r}\\
    \underline{r_2}=\underline{R}-\frac{m_1}{m}\underline{r}
\end{cases}$$
Since the external force is assumed to be zero, $\underline{R}$ moves with constant velocity.
Consider $\ddot{r}$, then $\ddot{r}=\underline{F_{12}}/m_1-\underline{F_{21}}/m_2=(1/m_1+1/m_2)\underline{F_{12}}$.
Hence
$$\mu\underline{\ddot{r}}=\underline{F_{12}}(\underline{r}),\mu=\frac{m_1m_2}{m_1+m_2}$$
Here $\mu$ is called the reduced mass.
In the case of the gravitational force, we have
$$\mu\underline{\ddot{r}}=-\frac{Gm_1m_2}{|\underline{r}|^3}\underline{r}\implies\underline{\ddot{r}}=-G(m_1+m_2)\frac{\underline{r}}{|\underline{r}|^3}=-\frac{GM}{|\underline{r}|^3}\underline{r}$$
which is just like the motion of two particles entirely due to a mass $M$ at the origin.
So both masses perform orbits with similar shape but different sizes.
\subsection{Variable Mass Problem}
Think of a rocket whose mass decreases as it moves due to the exhausted mass.
So its mass itself is variable.
So we need to apply Newton's Second Law to the whole system including the exhausted mass.
Suppose the mass and the velocity of the rocket is $m(t),v(t)$.
And the exhausted mass has a speed $u$ relative to the rocket when leaving the rocket.
At time $t$, when we look at this instant only, we can ignore what happened in the past, hence after a small time interval $\delta t$, mass of $m(t)=m(t+\delta t)$ is exhausted with speed $v(t)-u+o(\delta t)$.
By conservation of momentum,
$$m(t+\delta t)v(t+\delta t)+(m(t)-m(t+\delta t))(v(t)-u+o(\delta t))=m(t)v(t)$$
Hence
$$(mv^\prime+m^\prime u)\delta t\approx m(t+\delta t)(v(t+\delta t)-v(t))+(m(t+\delta t)-m(t))u+o(\delta t)=0$$
Since $\underline{F}=\underline{\dot{p}}$, it generalises to
$$mv^\prime+m^\prime u=F$$
where $F$ is the total external force exerted on the rocket.
This is called the rocket equation.
If $F=0$, we have $mv^\prime+m^\prime u=0$ which we can solve to get $v=v_0+u\log(m_0/m(t))$.


\title{Experimental Laboratory 3\\Analysis of the hydrodynamic forces acting on a cylinder in steady free surface flow}
\author{
        Sergio M. Vanegas A.\\
        Francesco de Pas\\
                Department of Mathematics\\
        Polimi---Politecnico di Milano\\
        Milano, Italia
}
\date{\today}

\documentclass[12pt]{article}

\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{siunitx}

\begin{document}
\maketitle

\begin{abstract}

        Goal of this test case is to investigate the drag and lift forces acting on a cylinder submerged in a steady-state free-surface water flow. The experiments have been performed in the water channel facility of the Hydraulics Laboratory, and the two force components (horizontal and vertical) have been measured through a balance. In the case study proposed, the Reynolds number of the cylinder $Re=DU_\infty/\nu$ is within the range of the “sub-critical regime”\footnote{Note that the classification of flow regimes discussed in the class lecture refers to unconfined flows. This is not the case of this experiment, in which the cylinder is located in a water channel with finite size cross section. However, it is reasonable to expect some similar behavior to the unconfined case.}; therefore, it will be not surprising to notice that the flow separates at a certain distance from the front stagnation point, causing a recirculation zone behind it, and that an oscillating wake is created by the shedding of two counter-rotating vortexes. As a result, also drag and lift will show an oscillating behavior.\cite{FL:07}

\end{abstract}

\section{Introduction}

        The scheme of the experiment is reported in Figure~\ref{fig:reference} here below. The balance is fixed to the ground and connected to the cylinder through the endplates. The hydrodynamically shaped endplates allow to hold the cylinder and ensure some sort of “two-dimensional flow” around it by suppressing the three-dimensional effects at the cylinder ends. Two load cells are installed inside the balance, one for measuring the horizontal force and the other for measuring the vertical force. The load cells provide an output voltage, which is linearly proportional to the applied force.

        \begin{figure}[ht!]
                \centering
                \includegraphics[width=\textwidth]{Setup.png}
                \caption{Sketch of the experiment}
                \label{fig:reference}
        \end{figure}

        The calibration of the balance has been performed after the installation of the endplates and the cylinder on the balance, by applying weight standards to the cylinder without water in the channel. When developing the calibration function, it was taken into account that the real forces experienced by the cells are not only those produced by the applied load, but they also include the weight of the structure, and other small contributions related with the deformability of the structure. The calibration function has been determined in such a way that the condition $F_x=0$, $F_y=0$ corresponds to the absence of applied (external) forces, net of the weight and the small deformability-related contributions.

        When water flows in the channel, assuming that the dynamic forces on the endplates is negligible since they are hydrodynamically shaped, the horizontal external force $F_x$ is equal to the drag force acting on the cylinder, $F_D$. Conversely, the vertical external force $F_y$ is equal to the sum of the lift force acting on the cylinder $F_L$ and the buoyancy force acting on the cylinder and the endplates, $F_B$. Thus, whereas $F_D$ is simply taken as the calibration output $F_x$, $F_L$ will be given as $F_y - F_B$. The buoyancy force, $F_B$, could be theoretically calculated by multiplying the volume of the immersed parts (cylinder and part of the endplates) by the specific weight of water. However, since knowing all the geometrical details with high accuracy is not trivial, directly measuring $F_B$ with the balance appears a preferred option. This is achieved by making a test in still water with the same level of the flowing-water test. Since no drag and lift forces play a role in the static test, in this case the horizontal external force $F_x$ will be zero and the vertical external force $F_y$ will be equal to $F_B$.

        The input data of the problem is summarized in Table~\ref{tab:input_data}.

        \begin{table}[ht!]
                \centering
                \begin{tabular}{llll}
                        \hline
                        \textbf{Symbol}     & \textbf{Parameter}        & \textbf{Value}        & \textbf{Units}        \\ \hline
                        \textit{B}      & Width of the channel  & 0.5   & m     \\
                        \textit{D}      & Diameter of the Cylinder      & 0.06  & m     \\
                        \textit{L}      & Width of the Cylinder & 0.185 & m     \\
                        \textit{t}      & Thickness of the endplates    & 0.002 & m     \\
                        \textit{b}      & Length of the endplates       & 0.180 & m     \\
                        \textit{h}      & \begin{tabular}[c]{@{}l@{}}Water level in the channel\\ upstream of the cylinder\end{tabular} & 0.45  & m     \\
                        \textit{$h_b$}    & \begin{tabular}[c]{@{}l@{}}Distance of the cylinder wall\\ from the channel bottom\end{tabular}      & 0.18 & m     \\
                        $f_s$   & Sampling frequency    & 200   & Hz    \\
                        \textit{Q}       & Volumetric flow rate of water & 75    & L/s   \\
                        \textit{$\rho$} & Density of water  & 998   & $\text{Kg}/m^3$       \\
                        \textit{$\mu$}   & Dynamic viscosity of water    & 0.001 & Pa$\cdot$s  \\ \hline
                \end{tabular}
                \caption{Input Data}
                \label{tab:input_data}
        \end{table}

        The complete set of acquisition data is provided in the MATLAB\\ workspaces from Table~\ref{tab:workspace}. In each workspace, the values of $F_x$ and $F_y$ are provided in the form of vectors. These values have already been converted from the voltage output of the cells through the calibration functions, as explained previously.

        \begin{table}[ht!]
                \centering
                \begin{tabular}{|l|l|}
                        \hline
                        \textbf{Filename}       & \textbf{Condition}    \\ \hline
                        \texttt{FORCEdata\_nowater.mat}  & \begin{tabular}[c]{@{}l@{}}Cylinder and endplates, no water in the\\ channel\end{tabular}     \\ \hline
                        \texttt{FORCEdata\_stillwater.mat} & \begin{tabular}[c]{@{}l@{}}Cylinder and endplates, still water in the\\ channel\end{tabular}        \\ \hline
                        \texttt{FORCEdata\_flow.mat}       & \begin{tabular}[c]{@{}l@{}}Cylinder and endplates, flowing water in\\ the channel\end{tabular}      \\ \hline
                        \texttt{FORCEdata\_NatOsc.mat} & \begin{tabular}[c]{@{}l@{}}Cylinder and endplates, still water in the\\ channel, cylinder hit once manually\end{tabular}        \\ \hline
                \end{tabular}
                \caption{MATLAB workspace descriptions}
                \label{tab:workspace}
        \end{table}

        The remainder of the report is organized as follows: in Section~\ref{sec:setup}, we approximate the channel Bulk velocity, the setup's Reynolds number and the Buoyancy Force, which will be fundamental for the analysis of the experimental data; in Section~\ref{sec:static} we analyze the Reynolds-Averaged Forces and Coefficients, as well as its measurement error; in Section~\ref{sec:dynamic} we identify the vortex shedding frequency and compare it to the natural frequencies of the balance structure in still water; finally, in Section~\ref{sec:optional} we further analyze the oscillations of the Lift Force and the hypothetical error induced by a variation in the setup's water level.

\section{Parameter Acquisition} \label{sec:setup}

        Since the experiments involve a water flow in a finite size channel, $ U_b \neq U_\infty $; nevertheless, it is a reasonable first approximation for our case of study. We approximate the channel bulk velocity through the expression in Equation~\ref{eq:Ub}. Then, we use this value to approximate the Reynolds number as in Equation~\ref{eq:Re}.

        \begin{equation} \label{eq:Ub}
                U_b = \frac{Q}{B h} = \SI{3.333E-1}{\metre \per \second}
        \end{equation}

        \begin{equation} \label{eq:Re}
                \text{Re} = \frac{D U_\infty}{\nu} \approx \frac{D U_b}{\nu} = \num{1.996E4}
        \end{equation}

        Using the data from \texttt{FORCEdata stillwater.mat}, we averaged the vertical force registered by the sensor when there is no flow, which corresponds to the buoyancy force exerted by the medium: \SI{7.325E0}{\newton}. This value will be subtracted from the registered force from now on in order to get the real value of the force exerted by the flow along the vertical axis.

\section{Reynolds-Averaged Analysis} \label{sec:static}

        We then loaded \texttt{FORCEdata\_flow.mat} and averaged the data over time in order to get the Reynolds-Averaged value of the forces along x and y (\SI{9.157E-1}{\newton} and \SI{-2.181E-2}{\newton} respectively). Normalizing these values with the formula in Equation~\ref{eq:coeff}, we get the Reynolds-averaged Drag and Lift Coefficients (\num{1.488E0} and \num{-3.543E-2} respectively).

        \begin{equation} \label{eq:coeff}
                C_{D,L} = \frac{F_{D,L}}{\frac{1}{2} \rho A U_b^2} , A=LD
        \end{equation}

        In order to determine the uncertainty of the above coefficients, we made use of the \textit{Error-Propagation Law}: let $y=y(x_1,x_2,\dots,x_n)$ be the quantity of interest; then, the uncertainty $u(y)$ can be estimated as $$u(y) = \sqrt{\left(\frac{\partial y}{\partial x_1} u(x_1)\right)^2 + \left(\frac{\partial y}{\partial x_2} u(x_2)\right)^2 + \dots + \left(\frac{\partial y}{\partial x_n} u(x_n)\right)^2}$$

        In our specific case, we can estimate the uncertainties of interest as in Equation~\ref{eq:uncertainty}, particularly the uncertainties of the Drag and Lift coefficients (\num{9.229E-2} and \num{4.064E-2} respectively). It is worth noting that the Lift coefficient uncertainty is comparable to its magnitude, meaning that the expected 0 average value is well within the estimation's interval of accuracy. On the other hand, the Drag coefficient uncertainty is two order of magnitude below its magnitude, meaning that we can rely on the calculated value.

        \begin{align} \label{eq:uncertainty}
                \begin{cases}
                        u(A) &= \sqrt{\left(D u(L)\right)^2 + \left( L u(D) \right)^2}\\
                        u(U_b) &= \sqrt{\left(\frac{1}{B h} u(Q)\right)^2 + \left(\frac{-Q}{B^2 h} u(B)\right)^2 + \left(\frac{-Q}{B h^2} u(h)\right)^2}\\
                        u(C_{D,L}) &= \sqrt{\left(\frac{1}{\frac{1}{2} \rho A U_b^2} u(F_{D,L})\right)^2 + \left(\frac{-F_{D,L}}{\frac{1}{2} \rho A^2 U_b^2} u(A)\right)^2 \left(\frac{-2 F_{D,L}}{\frac{1}{2} \rho A U_b^3} u(U_b)\right)^2}
                \end{cases}
        \end{align}

\section{Dynamic Analysis} \label{sec:dynamic}

        Once we were done with the static analysis, we loaded both \texttt{FORCEdata flow.mat} and \texttt{FORCEdata NatOsc.mat}. We then applied an FFT to both datasets' Vertical Force and extracted the highest peak's frequency location, revealing that the Vortex-shedding frequency and Natural oscillation frequency were \SI{1.008E0}{\hertz} and \SI{3.126E-2}{\hertz} respectively. As we can clearly notice, these values are 2 orders of magnitude apart from each other, making it clear that the oscillations we register during the flow correspond to the Vortex-shedding characteristic frequency instead of a natural resonance.

\section{Optional Questions} \label{sec:optional}

        After obtaining the characteristic frequencies of the system, we wanted to determine the amplitude of the flow oscillations along the vertical axis; in order to do this, a noise-free signal (or at least a high SNR) was required.

        We first filtered the data from the \texttt{FORCEdata flow.mat} dataset using a Low-Pass filter with a cutoff frequency of double the Vortex-shedding one; a comparison can be observed in Figure~\ref{fig:filtered}.

        \begin{figure}[ht!]
                \centering
                \includegraphics[width=\textwidth]{Filtered.png}
                \caption{Original signal vs Filtered signal}
                \label{fig:filtered}
        \end{figure}

        With the filtered signal, we extracted the amplitude using 2 different methods:

        \begin{itemize}
                \item Half the difference between the averaged maxima and minima ($a_\text{peak} = \SI{4.732E-1}{\newton}$).
                \item $\sqrt{2}$ times the RMS value of the signal ($a_\text{RMS} = \SI{5.198E-1}{\newton}$).
        \end{itemize}

        Using these values, we calculated the Fluctuating Lift coefficient as in Equation~\ref{eq:lift_p}, yielding $\num{7.689E-1}$ and $\num{8.446E-1}$ respectively. Regardless of the method, it is worth noting that this quantity is one order of magnitude above the Reynolds-averaged Lift coefficient, which is coherent with the studied theory.

        \begin{equation} \label{eq:lift_p}
                C_L' = \frac{a_L}{\frac{1}{2} \rho A U_\infty^2}
        \end{equation}

        Regarding the hypothetical errors, we first calculated the difference in Buoyancy Force induced by the bigger endplate portion of mass submerged resulting from the proposed water level variation as in Equation~\ref{eq:dFB}. Adding this value to the previously registered Force, we repeated the calculations for the Reynolds-averaged Drag and Lift coefficients and for the Fluctuating Lift coefficient and compared it to the original values. As expected, the Static Drag coefficient does not change at all, since the effect of the water level variation only has an effect along the vertical axis. Nevertheless, for this very reason both the Static and Fluctuating\footnote{Only if the RMS method is used.} Lift coefficients suffer a variation of 64\% and 0.2\% respectively. Such a high relative error in Static lift coefficient is due to the fact that a 0 average value for the vertical force is expected once the Buoyancy Force has been subtracted, instead for the fluctuating one, since no new fluctuation stimula are inserted, it is reasonable it remains almost the same.

        \begin{equation} \label{eq:dFB}
                \Delta F_B = - (2 t b) \rho g \Delta h \; , \; \Delta h = \SI{2E-3}{\metre}
        \end{equation}

\bibliographystyle{abbrv}
\bibliography{main}

\end{document}


    \filetitle{pct}{Percent rate of change}{tseries/pct}

	\paragraph{Syntax}\label{syntax}

\begin{verbatim}
X = pct(X)
X = pct(X,K,...)
\end{verbatim}

\paragraph{Input arguments}\label{input-arguments}

\begin{itemize}
\item
  \texttt{X} {[} tseries {]} - Input tseries object.
\item
  \texttt{K} {[} numeric {]} - Time shift over which the rate of change
  will be computed, i.e.~between time t and t+k; if not specified
  \texttt{K} will be set to \texttt{-1}.
\end{itemize}

\paragraph{Output arguments}\label{output-arguments}

\begin{itemize}
\itemsep1pt\parskip0pt\parsep0pt
\item
  \texttt{X} {[} tseries {]} - Percentage rate of change in the input
  data.
\end{itemize}

\paragraph{Options}\label{options}

\begin{itemize}
\itemsep1pt\parskip0pt\parsep0pt
\item
  \texttt{'outputFreq='} {[} \texttt{1} \textbar{} \texttt{2} \textbar{}
  \texttt{4} \textbar{} \texttt{6} \textbar{} \texttt{12} \textbar{}
  \emph{empty} {]} - Convert the rate of change to the requested date
  frequency; empty means plain rate of change with no conversion.
\end{itemize}

\paragraph{Description}\label{description}

\paragraph{Example}\label{example}

In this example, \texttt{x} is a monthly time series. The following
command computes the annualised rate of change between month t and t-1:

\begin{verbatim}
pct(x,-1,'outputfreq=',1)
\end{verbatim}

while the following line computes the annualised rate of change between
month t and t-3:

\begin{verbatim}
pct(x,-3,'outputFreq=',1)
\end{verbatim}


\chapter{Relativity}

\paragraph{Needed before reading this chapter}
Make sure that you have understood Chapter~\ref{chp:geometry}~(p.~\pageref{chp:geometry}).

\UnorderedList{
\item We see every moving clock ticking slower than our clock.
}

When reality and theory disagree, reality always wins.
We celebrate every time we falsify a theory.
It means that our knowledge is building.

To talk about relativity, we need \emph{analytic geometry},
which allows us to use numbers to describe locations, shapes, and other geometrical concepts.

After reading this chapter, you should be able to:
\UnorderedList{
\item craft a coordinate system
\item use vector to describe relative positions/displacements
\item calculate the time dilation, length contraction, momentum, and kinetic energy of an object moving in spacetime
\item describe the curvature of spacetime due to a point mass
\item visualize the Schwarzschild metric
}

\section{Calculating the Lorentz boost}

\index{Lorentz transformation}%
\index{Lorentz boost}%
Let \(c\) be the speed of light.
The \emph{Lorentz boost} of an object moving with constant speed \(v\) is \(\gamma(v)\) where
\Formula{
    \gamma(v) = \frac{1}{\sqrt{1 - \frac{v^2}{c^2}}}.
}
What does it mean?\footnote{\url{https://en.wikipedia.org/wiki/Lorentz_transformation\#Physical_implications}}

If you are interested in the derivation of the Lorentz transformation,
see \S\ref{sec:derive-lorentz-transform} (p. \pageref{sec:derive-lorentz-transform}) \emph{later}.
Don't do it now.

% https://en.wikipedia.org/wiki/Lorentz_transformation#boost
\ExerciseAnswer{Compute the slowing down of a clock that is moving at half the speed of light.
How many tick does the moving clock make for each tick that a stationary clock makes?
What if the moving clock's speed is \(c/4\)?
What if the moving clock's speed is \SI{100}{km/h}?
Hint: A handy conversion factor to remember is \(\SI{18}{km/h} = \SI{5}{m/s}\).
}{TODO}

\ExerciseAnswer{Exercise? Which clock is slower?
\(A\) is resting and \(B\) is moving.
\(A\) sees that \(B\)'s clock ticks slower.
But from \(B\)'s point of view,
\(A\) is moving and \(B\) is resting,
so \(B\) sees that \(A\)'s clock ticks slower.
Thus, which clock ticks slower?
}{Is this question even valid?}

\ShowAnswers

Time dilation: the faster a clock moves, the slower it ticks.

% this has a point?
% http://alternativephysics.org/book/index.htm

% Disproved by Schutz:
% Why Time Dilation must be Impossible:
% because it's impossible to tell which is moving faster than which,
% because the frame of reference itself could be moving.
% http://alternativephysics.org/book/TimeDilation.htm

% https://physics.stackexchange.com/questions/18867/how-does-time-dilation-work-without-a-privileged-reference-frame
% https://www.reddit.com/r/askscience/comments/1oej1u/how_do_we_pick_the_right_frame_of_reference_for/
% https://en.wikipedia.org/wiki/Twin_paradox#Resolution_of_the_paradox_in_special_relativity

\emph{Minkowski spacetime}?

\emph{World line} is ...

Proper time?

\subsection{Calculating time dilation}

\subsection{Calculating length contraction}

\subsection{Calculating the vector Lorentz transformation}

\section{Understanding rotation in Minkowski space}

\section{???}

\section{Understanding the stress-energy tensor}

\section{???}

\section{Understanding Einstein field equations}

\paragraph{Key idea}
Mass bends spacetime.

As energy at a point increases, spacetime bends more there.

% https://en.wikiversity.org/wiki/General_relativity
% https://en.wikipedia.org/wiki/Riemann_curvature_tensor
% Notation
% https://en.wikipedia.org/wiki/Ricci_calculus

A \emph{tensor} is ...

% FIXME copied from wikipedia
The tensor form of the Einstein field equations is%
\footnote{\url{https://en.wikipedia.org/wiki/Einstein_field_equations}}
\Formula{
    R_{ij} - \frac{1}{2} R g_{ij} + \Lambda g_{ij} = \frac{8\pi G}{c^4} T_{ij}
}
where \(R_{ij}\) is the Ricci curvature tensor, \(R\) is the scalar curvature, \(g_{ij}\) is the metric tensor,
\(\Lambda\) is the cosmological constant, \(G\) is Newton's gravitational constant, \(c\) is the speed of light in vacuum,
and \(T_{ij}\) is the stress–energy tensor.

\paragraph{Exercise}
Describe the bending of space due to a point mass.

\subsection{Calculating black hole event horizon radius?}

% https://en.wikipedia.org/wiki/John_Michell_(natural_philosopher)#Black_holes

In 1783, John Michell wrote about \emph{dark stars},
an object so heavy that light can't escape it?

\section{Calculating gravitational lensing}

% \section{Hawking radiation}

% \section{Black hole thermodynamics}

\section{Deriving Einstein field equations}

(To be done.)

\section{Relativity}

\subsection{Some basic terms}

% Read Landau & Lifshitz relativity volume?

A \emph{spacetime} \(M\) is a four-dimensional space.

An \emph{\(M\)-event} is a point in \(M\).

An \emph{\(M\)-frame} is an invertible function \(\Real^4 \to M\).
Such frame assigns a unique coordinate tuple to every event.

Let \(A : \Real^4 \to M\) be an \(M\)-frame.

Let \(B : \Real^4 \to M\) be an \(M\)-frame.

Let \(E : M\) be an \(M\)-event.

Let \(t \in \Real\).

Let \(x \in \Real^3\).

The notation \(E = A(t,x)\) means that
the event \(E\) \emph{happens} at \emph{\(A\)-time} \(t\) and \emph{\(A\)-position} \(x\).
It means that, \emph{from \(A\)'s point of view},
the event happens at time \(t\) and position \(x\).
We also say that such \(t\) is the \emph{\(A\)-time of \(E\)}
and such \(x\) is the \emph{\(A\)-position of \(E\)}.

We can write unqualified \emph{event} and \emph{frame} to mean \emph{\(M\)-event} and \emph{\(M\)-frame}
if it's clear from context that the spacetime being discussed is \(M\).
Similarly, we can write unqualified \emph{time} and \emph{position} to mean \emph{\(A\)-time} and \emph{\(A\)-position}
if it's clear from context that the frame being discussed is \(A\).

\emph{Observer} is another word for \emph{frame}.

\emph{Time} is measured by a \emph{clock}.

Time orders (sequences) events.

The \emph{position} of an object is where it is in a frame.

\emph{Distance} is measured by a \emph{ruler}.

% https://en.wikipedia.org/wiki/Inertial_frame_of_reference

\subsection{Motion and trajectory}

How do we describe motion?

Let \(A\) be an \(M\)-frame.

Let \(B\) be an \(M\)-frame.

Let \(P\) be a moving object with negligible size.

We describe \emph{A's account} of the motion of \(P\) as
\enquote{The \emph{\(A\)-position} of \(P\) at \emph{\(A\)-time} \(t\) is \(x(t)\).}

% TODO clear up

The \emph{\(M\)-trajectory} of the object \(P\)
is the set \( \{ A(t,x(t)) ~|~ t \in \Real \} \subseteq M \).
It means that at \(A\)-time \(t\), the \(A\)-position of \(P\) is \(x(t)\).
The \emph{\(A\)-velocity} of \(P\) is the derivative of that \(x\).
For example, if \(x(t) = vt + x_0\),
then \(A\) sees that \(P\) is moving with constant velocity \(v\).
The function \(x\) is \(A\)'s description of \(P\)'s motion.
Thus, velocity is also relative, because time and position are relative,
and velocity is defined in terms of time and position.

\index{definitions!stationary}%
\index{stationary!definition}%
An object is \emph{\(A\)-stationary} iff its \(A\)-velocity is constantly zero.

\(A\) and \(B\) may disagree about the motion of \(P\), but \(P\)'s \(M\)-trajectory is the same:
\( \{ A(t,x(t)) ~|~ t \in \Real \} = \{ B(u,y(u)) ~|~ u \in \Real \} \).
The problem is to state \(u\) and \(y\) in terms of \(t\) and \(x\).
It can be thought that the trajectory is the unknowable objective existence of the object?

\emph{\(M\)-world-line} is synonym of \emph{\(M\)-trajectory}.

\section{Deciding whether two events are simultaneous}

What happens at the same time according to an observer?

Two \(M\)-events are \emph{\(A\)-simultaneous} iff they have the same \(A\)-time.
Formally, $A(t,x)$ and $A(u,y)$ are \emph{\(A\)-simultaneous} iff $t = u$.

The set of all events that happen at \(A\)-time \(t\) is \(S_A(t) = \{ A(t,x) ~|~ x \in \Real^3 \}\).

The simultaneity relationship forms an equivalence class?
Isochrone?

Let the \(A\)-velocity of \(B\) be constant \(b\).

From \(A\)'s point of view, at time \(t\),
the light has traveled a distance \(ct\).
Thus, \(S_A(t) = \{ (t,x) ~|~ \norm{x} = ct \}\).
\(X_A(t) = \{ x ~|~ \norm{x} = ct \}\).

From \(B\)'s point of view, at time \(t\),
the light has traveled a distance \(ct\),
but every point in space has moved by \(-vt\).
Thus, the set of all \(B\)-simultaneous events at \(B\)-time \(t\) is
\( S_B(t) = \{ (t,x) ~|~ \norm{x - vt} = ct \} \).
\(X_B(t) = \{ x ~|~ \norm{x - vt} = ct \}\).

Space homogeneity principle:
\(d(x+h,y+h) = d(x,y)\).
translating a rod preserves its length.
The distance between two points depends only on the relative position of the points.

Time homogeneity principle is similar to space homogeneity principle.

Plot \((t,x)\) satisfying \(\norm{x-vt} = ct\).
In two-dimensional space, it is a pair of lines.
In three-dimensional space, it is a cone.
\begin{align*}
    \norm{x-vt}^2 &= \sum_{k \in \{1,2,3\}} (x_k - v_kt)^2
\end{align*}

From \(B\)'s point of view, at time \(t\),
after duration \(dt\),
the light has traveled a distance \(c~dt\),
but every point in space has moved by \(-v(t)~dt\).
Thus, the set of all \(B\)-simultaneous events at \(B\)-time \(t + dt\) is
\( S_B(t + dt) = \{ (t,x) ~|~ \norm{x - v(t)~dt} = c~(t + dt) \} \).

How do we measure the distance to somewhere?
We fire a light at it.
The time light takes to get there is proportional to the distance.

A stationary observer \(A\) fires light everywhere.
According to \(A\), everything in \(\{ x ~|~ \norm{x} = ct \}\)
happens at the same \(A\)-time \(t\).

Two events are \emph{\(A\)-simultaneous} iff their \(A\)-times match.

TODO
What does `synchronized' mean?
What does it mean that two clocks are synchronized?

% from TED history of the world: Matter is congealed energy.

The water waves we see propagate in water,
the sound waves we hear propagate in air,
so it's tempting to guess that the light (the optical waves) we see propagate in
\emph{luminiferous aether} (``fresh air that carries light''), who coined that name?
The wave in moving water?
The \emph{Michelson\textendash{}Morley aether interferometry experiment} tried to measure
the velocity of the Earth with respect to the aether,
but they found no significant differences.
Who threw away the aether idea?
Light does not need a medium to propagate.

\subsection{Inertial frame}

What is a \emph{moving frame}?
How do we formalize it?
Given what \(A\) sees, how do we compute what \(B\) sees?

Let \(A\) and \(B\) agree on the origin: \(A(0,0) = B(0,0)\).

Let the \(A\)-velocity of \(B\) be constant \(b\).

Let the \emph{target} \(T\) be an \(A\)-stationary object at \(A\)-position \(x\).

Let \(E = A(0,0) = B(0,0)\) be the event \enquote{the light fired from the origin}.

Let \(F = A(t,x) = B(t',x')\) be the event \enquote{the light arrived at the target}.

\(A(0,x-ct) = A(0,0)\)

\(B(0,x'-c't') = B(0,0)\)

Let \(c\) be the \(A\)-velocity of the light fired from \(E\) to \(F\).

Thus \(x = ct\). Thus \(c\) and \(x\) have the same direction.

Then \(A(0,x) = B(0,x')\) is the initial event of \(T\).

Then \(F = A(t,x) = B(t',x' - vt')\).

Then \(F = A(t,ct) = B(t',x' - vt')\).

Every \emph{object} has a position in space.

\emph{Law of the velocity of two observers}:
If \(A\) sees \(B\) moving with velocity \(v\),
then \(B\) sees \(A\) moving with velocity \(-v\).
(The \(A\)-velocity of \(B\) is the negation of the \(B\)-velocity of \(A\).)

How do we measure distance?

To measure distance, we use light.

Let \(P\) be an \(A\)-position.

Let \(Q\) be an \(A\)-position.

In frame \(A\),
if light traverses \(PQ\) in duration \(t\),
then the \(A\)-length of \(PQ\) is \(d_A(P,Q) = c t\).

If light takes the same \(A\)-duration to traverse \(OA\) and \(OB\),
then \(OA\) and \(OB\) have equal \(A\)-length: \(d(O,A) = d(O,B)\).

Define \(S(O,q)\) as the set of every point whose distance from \(O\) is \(q\).
Formally, \(S(O,q) = \{ P ~|~ d(O,P) = q \}\).

Law: \(v_{AB} = -v_{BA}\).

To derive Lorentz transformation, we use three observers \(A,B,C\)
where \(A\) sees \(B\) moving but \(A\) sees \(C\) stationary.

An \emph{event} is a point \((t,x)\) in spacetime \(\Real \times \Real^3\).
Let \(A\) and \(B\) agree at \((0,0)\).
An observer is a frame is a chart is a coordinate system.
Let \(C_A(e)\) be the \(A\)-coordinates of \(e\).

Let \(E_A(t)\) be the set of all events that happen in \(A\)-time \(t\).
Then it is \(E_A(t) = \{ e ~|~ \exists x ~ C_A(e) = (t,x) \}\).

Let the position of \(M\) at \(O\)-time \(t\) be \(x(t)\).
If \(O\) emits light, and object \(M\) is moving with velocity \(v\),
then the light and \(M\) will meet at \(d(O,x_\text{meet})\)
where there exists \(t\) such that \(x(t) = x_\text{meet}\).
It is the intersection of a sphere and a line.

The distance takes two objects, not two points.
Let there be objects \(S, M, T\) (stationary, moving, and target).
According to \(S\), \(M\) is moving with velocity \(v\), and \(T\) is stationary.
Suppose that when \(S\) and \(M\) both coincided at \((t_0,x_0)\),
both of them fired a light at \(T\) (target).
\(S\) sees that \(d(S,T) = d(x_0,x_T)\).
\(M\) sees that \(d(M,T) = d(x_0,x_T - vu)\).

\subsection{Old text}

All lights that originate at \(A(t,x)\) reach \(A\)-position 0 simultaneously at \(A\)-time \(t + x/c\).
The set of all $\{ A(t,x) ~|~ \norm{x} = ct \}$ is the \(A\)-simultaneity surface at \(A\)-time $t$.
Two events in the same \(A\)-simultaneity surface happens at the same \(A\)-time.

Let O's firing light in all directions happens at $A=O(0,0)$
and the detection of that light by Q happens at $B = O(\vec{x},t)$.
If $\vec{x}$ is always the O-position of Q,
then
\[
t = x/c.
\]

Now suppose that $Q$ has constant O-velocity $\vec{v}$,
and the O-position of $Q$ at O-time 0 is $\vec{x}$.
Q's detection of light now happens at $B'=O(\vec{x}',t')$ instead, where
\begin{align*}
\vec{x}' = \vec{x} + \vec{v} t'
\\ c t' = \norm{\vec{x}'}
\end{align*}
due to the light speed constancy principle.

Suppose $\vec{v}$ and $\vec{x}$ are perpendicular to each other.
\begin{align*}
(x')^2 = x^2 + (vt')^2 = (ct')^2
\\ x^2 = (c^2-v^2)(t')^2
\\ t' = \frac{x}{\sqrt{c^2-v^2}}
\\ t' = \frac{x}{c \sqrt{1-(v/c)^2}} = \alpha x/c = \alpha t
\\ x' = \alpha x
\end{align*}

To help visualize this, we can use the spacetime diagram.
The x-axis is the distance from O-position zero.
The y-axis is the interval from O-time zero.

Suppose that they weren't perpendicular.
\begin{align*}
\vec{x}' = \vec{x} + \vec{v} t'
\\ c t' = x'
\\ x_k' = x_k + v_k t'
\\ c^2 (t')^2 = (x')^2
\\ = \norm{\vec{x} + \vec{v} t'}^2
\\ = x^2 + 2 t' \vec{x} \cdot \vec{v} + v^2(t')^2
\\ = x^2 + 2 t' \vec{x} \cdot \vec{v} + (v^2 - c^2)(t')^2
\\ t' = \frac{- 2 \vec{x} \cdot \vec{v} \pm \sqrt{(2 \vec{x}\cdot\vec{v})^2 - 4 (v^2 - c^2) x^2}}{2 (v^2 - c^2)}
\\ t' = \frac{\vec{x}\cdot\vec{v} + \sqrt{(\vec{x}\cdot\vec{v})^2 + (c^2 - v^2) x^2}}{c^2 - v^2}
\\ t' = \frac{\vec{x}/c\cdot\vec{v}/c + \sqrt{(\vec{x}/c\cdot\vec{v}/c)^2 + (1 - (v/c)^2) (x/c)^2}}{1 - (v/c)^2}
\\ t' = \frac{(x/c)(v/c) \cos \theta + \sqrt{((x/c)(v/c)\cos\theta)^2 + (1 - (v/c)^2) (x/c)^2}}{1 - (v/c)^2}
\\ t' = \frac{t(v/c) \cos \theta + \sqrt{(t(v/c)\cos\theta)^2 + (1 - (v/c)^2) t^2}}{1 - (v/c)^2}
\end{align*}

A light fired at $O(\vec{x},t)$ can be at any $O(\vec{x}+\vec{dx},t+dt)$
where $dx = c~dt$.

A light that O detects at $O(\vec{x},t)$ could come from any $O(\vec{x}-\vec{dx},t-dt)$ where
$dx = c~dt$.

Let M has constant O-velocity $\vec{v}$.
Let M pass $O(0,0)$.

A light that M detected at $O(\vec{v}t,t)$ could come from any $O(\vec{v}t-\vec{dx},t-dt)$ where $dx = c~dt$.
Therefore O observes that M must detect all such lights at the same M-time that corresponds to O-time $t$.
Therefore O observes that all such things must be M-simultaneous.

A light that O detected at $O(0,t)$ and M detected at $O(\vec{v}\tau,\tau)$
could come from any $O(-\vec{dx},t-dt)$ and $O(\vec{v}\tau-\vec{d\xi},d\tau)$ where $dx = c~dt$ and $d\xi = c~d\tau$.

A light that O detected at $O(0,0)$ and M detected at $O(0,\tau)$
could come from any $O(-\vec{dx},t-dt)$ and $O(\vec{v}\tau-\vec{d\xi},d\tau)$ where $dx = c~dt$ and $d\xi = c~d\tau$.

A light fired from $O(\vec{x},t)$ will be detected by O at $O(0,t)$ and by M at $O(\vec{v}\tau, \tau)$
where
\[
x = ct
\\
\norm{\vec{x} - \vec{v}\tau} = c\tau
\]

A light that M detected at $M(0,\tau)$ could come from any $M(\vec{d\xi},\tau-d\tau)$ where $d\xi = c~d\tau$.
A light that O detected at $M(-\vec{v}\tau,\tau)$ could come from any $M(-\vec{v}\tau+\vec{d\xi},\tau-d\tau)$ where $d\xi = c~d\tau$.

\[
O(0,0) = M(0,0)
\\ O(\vec{v}t,t) = M(0,\tau)
\\ M(-\vec{v}\tau,\tau) = O(0,t)
\]

This is the same case where everything else has constant M-velocity $-\vec{v}$.

A light fired at $M(\vec{x},t)$ can be at any $M(\vec{x}+\vec{dx},t+dt)$ where
\[
dx = c~dt
\]
according to light speed constancy principle.

However, $M(\vec{x},t)$ and $M(\vec{x}+\vec{v}u,t+u)$ are the same point in space for all $u$.
If, at $M(0,t+u)$, M detects a light fired from $M(\vec{x},t)$ (thus $u=x/c$),
then the firer actually was $M(\vec{x}+\vec{v}u,t)$.

Let $O(0,0) = M(0,0)$.
Let $O(\vec{v}t,t) = M(0,\tau)$.

Suppose that $O$ observes $M$ to be moving according to $\vec{p}$
where $\vec{p}(t) = \vec{a} + \vec{v}t$ is the O-position of $M$ at O-time $t$.
A light that $M$ detects at $O(\vec{p}(t),t)$ could come from any $O(\vec{p}(t)-\vec{dx},t-dt)$
where $dx = c~dt$.
A light from $O(\vec{x},t)$ will be detected by O at $O(0,t+x/c)$
and will be detected by M at $O(\vec{a}+\vec{v}(t+u)-\vec{x},t+u)$
where $\norm{\vec{a}+\vec{v}(t+u)-\vec{x}} = cu$.
If $\vec{x}=0$ and $t=0$, then it will be detected by M at $O(\vec{a}+\vec{v}u,u)$ where $\norm{\vec{a}+\vec{v}u}=cu$.

A light from $O(0,t)$ will be detected by M at $O(\vec{a}+\vec{v}u,u)$ where $\norm{\vec{a}+\vec{v}u} = c(u-t)$
A light from $O(\vec{x},0)$ will be detected by M at $O(\vec{a}+\vec{v}t-\vec{x},t)$ where $\norm{\vec{a}+\vec{v}t-\vec{x}} = ct$

\subsection{Frame transformation}

We \emph{describe frame transformation}.
We can write the equation \(A(t,x) = B(t',x')\) as \(A(t,x) = B(T(t,x), X(t,x))\)
with unknown functions \(T\) and \(X\).
We are trying to state \(t'\) in terms of \(t\) and \(x\).
We write \(A(t,x) = B(t',x')\) to mean that the \(A\)-coordinates \((t,x)\)
and the \(B\)-coordinates \((t',x')\) refer to the same \(M\)-event.
The same \(M\)-event can have different \(A\)-coordinates and \(B\)-coordinates.

\subsection{(being written)}

What is the \(A\)-distance traveled in \(A\)-duration \(dt\) by an object moving with constant \(A\)-velocity \(v\)?
It is \(\norm{v ~ dt} = \norm{v} ~ dt\).

How do we formalize the constancy of the speed of light?

\section{Special relativity}

Special relativity can be derived from Galileo's principle of relativity
and Einstein's principle of the universality of the speed of light.
\cite[p.~1]{schutz2009first}

\index{laws!relativity}%
\index{laws named after people!Galileo's principle of relativity}%
\emph{Galileo's principle of relativity}: No experiment can measure the absolute velocity of an observer.
There is no preferred inertial frame.
There is no special inertial frame.
There is no absolute motion.

\index{laws!universality of the speed of light}%
\index{laws named after people!Einstein's principle of the universality of the speed of light}%
\emph{Einstein's principle of the universality of the speed of light}:
The speed of light is the same for all inertial (non-accelerating) observers.
The origin of this postulate is \enquote{the law of electromagnetics is the same at all reference frames}
or \enquote{the law of physics is the same in all reference frames}.
Everyone sees the same Maxwell's equations.
Everyone measures the same speed of light,
regardless of how fast they are moving.
Did Einstein know the Michelson\textendash{}Morley experiment?

So what?
What are the consequences?

Lorentz transformation can be derived from the principle of the universality of the speed of light,
with the aid of a spacetime diagram?
What is a spacetime diagram?
Minkowski diagram.
% https://en.wikipedia.org/wiki/Minkowski_diagram
Hermann Minkowski introduced in 1908.

\section{Ramble}

Spacetime metric

% http://en.wikibooks.org/wiki/Special_Relativity/Simultaneity,_time_dilation_and_length_contraction

% http://en.wikisource.org/wiki/On_the_Electrodynamics_of_Moving_Bodies_(1920_edition)

Let $O$ be the type of frames and $M$ be the type of motions.
Define $m~x~y$ as the motion of $y$ as observed by $x$:
\[
m : O \to O \to M.
\]
Define $a~x~y$ as adding the motion $x$ to the frame $y$:
\[
a : M \to O \to O.
\]
A motion has spacetime distance elapsed as measured by a frame:
\[
s : O \to M \to S.
\]

A frame always looks stationary to itself.
\[
m~x~x = 0
\]
where $0$ is the null motion.

Inverse motion:
\[
m~x~y = -m~y~x
\]

$m$ looks like subtraction.

Transformation of frames.
\begin{align*}
m~(T~x)~y &= T^{-1}~(m~x~y)
\\ m~x~(T~y) &= T~(m~x~y)
\end{align*}

If the same transform is applied to both frames:
\[
m~x~y = m~(T~x)~(T~y)
\]

The order of transformation does not matter:
\begin{align*}
m~(T~x)~(U~y) &= T^{-1}~(U~(m~x~y)) = U~(T^{-1}~(m~x~y))
\end{align*}

Frame seeing another frame that sees yet another frame.
\[
m~x~z = m~x~y + m~y~z
\]
where $+$ is motion addition.

We see that motions form a monoid.

This motion is straightforward to imagine: $x~t = 3 t$.

A motion seen from another reference frame.

The space picture:
We can think of motion as a path in spacetime.
\[
\begin{bmatrix}t\\x\end{bmatrix}
\]

Force-view of pendulum.

\begin{align*}
F_x &= 0
\\
F_y &= -mg
\end{align*}

It is easier if we change the coordinate system.
We look from the bob's point of view
so that $(0,0)$ is always the bob
and $(0,1)$ is always the direction from the bob to the pivot.

$\theta=0$ represents negative y-axis.
Positive increment is counterclockwise.

\begin{align*}
F_{x'} &= -m g \sin \theta
\\ a_{x'} &= -g \sin \theta
\\ \frac{\partial^2 \theta}{\partial t^2} &= -g \sin \theta
\end{align*}

Field-view of pendulum.

\begin{align*}
P &= m g h
\\
K &= \frac{1}{2} m v^2
\end{align*}

We can describe a manifold by its tangent space.

% https://physics.stackexchange.com/questions/305857/lorentz-transformation-without-constant-speed-of-light-in-vacuum-reasonable/305861#305861

% Cite this paper: Nothing but Relativity
% https://arxiv.org/pdf/physics/0302045v1.pdf
% This paper is already cited by the above paper
% "One more derivation of the Lorentz transformation"
% https://fenix.tecnico.ulisboa.pt/downloadFile/3779571248372/Levy-Leblond_(76).pdf

% ramble

OpenStax University Physics Volume 3 \cite{openstaxphysics3}

TODO
Should we move this chapter earlier to introduce coordinates?
But this chapter should come after electromagnetism?

TODO
How do we describe the bending of space?
How do we describe an almost-Euclidean curved space?
The curvature of space?
By the metric?

(Rewrite: simultaneity hypersurface)
An event is a point in spacetime.
Let \(A,B,O\) be spatial points.
Two points \(A\) and \(B\) are \emph{\(O\)-simultaneous} iff a light fired from \(O\) reaches \(A\) and \(B\) at the same \(O\)-time.
If we are stationary, then our simultaneity hypersurface is a hypersphere.

A world line is a one-dimensional manifold in \(M\).

If \(A\) measures that a light has moved by spatial distance \(dx\), then \(A\)'s clock will have advanced by \(dt = dx / c\).

If \(A\) emits a light, and waits until a time interval of \(dt\) elapsed in his clock, then he will measure that the light has traveled a distance of \(c~dt\).

If \(A\)'s clock measures that a time interval of \(dt\) has elapsed, then the light will have moved by spatial distance \(dx = c ~ dt\).

%https://en.wikipedia.org/wiki/Postulates_of_special_relativity#Mathematical_formulation_of_the_postulates
Pseudo-Riemannian manifold
%https://en.wikipedia.org/wiki/Relativity_of_simultaneity#Accelerated_observers
radar-time/distance definition

The distance of an event \(A\) from another event \(B\) is the time required by light to reach \(B\) from \(A\).

From the point of view of the moving observer, he is stationary, and it is the world (everything else) that is moving towards him with velocity \(-v\). If he fire a ball of light, then after he measures time \(t\), then...

%https://en.wikipedia.org/wiki/Bondi_k-calculus
%https://en.wikipedia.org/wiki/Rapidity

%https://physics.stackexchange.com/questions/305857/lorentz-transformation-without-constant-speed-of-light-in-vacuum-reasonable/305861#305861

\section{Spacetime diagram and world-lines}

What is the coordinate system of an observer moving with constant velocity \(v\)?

A spacetime diagram represents the worldview of an observer?
Consider a spacetime diagram with one time dimension and one space dimension.
A point \((t,x)\) represents an event that occurs at time \(t\) and position \(x\) according to \(O\).
The horizontal is space coordinate \(x\).
The vertical is time coordinate \(t\).
Each event has a spacetime coordinate \((t,x,y,z)\).

Let \(A\) be at 0.
A light coming from a distance \(x\) from \(A\) will reach \(A\) after \(x/c\) time.

If \(A\) fires a light, let the light \(A\)-velocity be \(c\)
(a vector whose magnitude is the speed of light),
then after \(A\)-time-interval \(dt\),
the light will have traveled an \(A\)-distance of \(\norm{c ~ dt}\).
But \(B\) sees \(A\)-velocity \(c'\) and the light has traveled an \(A\)-distance of \(\norm{c' ~ dt - v ~ dt}\) from \(B\).

Speed is distance divided by time.

We can measure distance and time:
fire a light, and wait for its reflection to come back.
If \(t\) time elapsed until we measure the reflection, then the round-trip distance traveled by the light is \(ct\).

\emph{The same point in spacetime is assigned different coordinates.}

How do we know that two different coordinate tuples refer to the same point in spacetime?

Let \(M\) be the event space.
An event is a 4-tuple \((t,x,y,z) \in \Real^4\).
A coordinate system is a bijective mapping \(\Real^4 \to M\).
Let \(C_A\) and \(C_B\) be coordinate systems.
The same event \(e = C_A^{-1}(p_A) = C_B^{-1}(p_B)\).
How can we know that \(p_A\) and \(p_B\) map to the same event?

If \(A\) measures a constant-velocity object at \(C_A^{-1}(t_1,x_1)\) and \(C_A^{-1}(t_2,x_2)\),
then the velocity of the object is \(C_A^{-1}\left(\frac{x_2-x_1}{t_2-t_1}\right)\).

Two observers \(B\) and \(C\) move with the same \(A\)-velocity \(v\).
\(B\) fires a light to \(C\).

Let \(e_k\) be \(k\)'s coordinate system.
Thus \(e_A p = e_B q\) means that \(p\) and \(q\) happen at the same point in spacetime.

An observer is a coordinate system?

The \emph{\(A\)-world-line} of an object \(P\) moving with constant \(A\)-velocity \(v\)
is \( wlPA = \{ (t, x_0 + v t) ~|~ t \in \Real \} \)
where \(x_0\) is where the object is at \(A\)-time 0.
That line is the trajectory of \(P\) in \(A\)'s coordinate system.
Iff \(P\) is a light, then \(\norm{v} = c\).

TODO How do we add velocities in special relativity?

\section{What?}

An observer brings a clock and a light detector with him.
He determines the location
of another object by measuring how long his clock elapses
between his firing a light and his detecting its reflection.
If he fires a light with direction $\hat{x}$
when his clock says $t$ and
detects its reflection with direction $-\hat{x}$ when his clock says $u$,
then he infers that his light hit the object when his clock said $(t+u)/2$,
and he infers that the object was at $\hat{x} c(u-t)/2$ when his light hit the object;
he assumes that the speed of light is constant.

An observer measures the velocity of another object by firing two lights:
the first with direction $\hat{x}$ when his clock says $t$,
and the second with direction $D\hat{x}$ ($\hat{x}$ rotated a little) when his clock says $t + dt$.
If he detects the first reflection when his clock says $u$
and he detects the second reflection when his clock says $u + du$,
then he infers that his first light hits the object at $\hat{x} c(u-t)/2$ when his clock says $(t+u)/2$
and his second light hits the object at $D\hat{x} c(u-t+du-dt)/2$ when his clock says $(t+dt+u+du)/2$,
and therefore he infers that the object has displaced by
$D\hat{x} c(u-t+du-dt)/2 - \hat{x} c(u-t)/2$
while his clock has elapsed by $(dt+du)/2$.
We rearrange the displacement:
\begin{align*}
& D\hat{x} c(u-t+du-dt)/2 - \hat{x} c(u-t)/2
\\ &= \frac{c\hat{x}}{2} ((u-t+du-dt)D - (u-t)I)
\\ &= \frac{c\hat{x}}{2} ((u-t)(D-I) + (du-dt)D)
\end{align*}
therefore he measures that the object's average velocity between $t$ and $t+dt$ was:
\begin{align*}
&\frac{\frac{c\hat{x}}{2} ((u-t)(D-I) + (du-dt)D)}{(dt+du)/2}
\\ &= \frac{c\hat{x} ((u-t)(D-I) + (du-dt)D)}{dt+du}
\end{align*}
which becomes this if $D=I$ ($\vec{v} \cdot \hat{x} = 0$):
\begin{align*}
&\frac{\frac{c\hat{x}}{2} ((u-t)(D-I) + (du-dt)D)}{(dt+du)/2}
\\ \vec{v} &= \frac{du-dt}{du+dt} c \hat{x}
\\ -v/c &= \frac{du-dt}{du+dt}
\\ (du+dt) v/c &= dt-du
\\ (1+v/c)du &= (1-v/c)dt
\\ \frac{du}{dt} &= \frac{1-v/c}{1+v/c} = \frac{c-v}{c+v}
\end{align*}

When he detects a light when his clock says $t$,
he knows the direction where the light is going ($\hat{x}$),
and thus he knows the direction the light came from ($-\hat{x}$),
but he does not know where exactly in his spacetime whence the light originates;
the light could come from any $\hat{x}u$ when his clock said $t-u$, for all real $u$.

Now we introduce coordinate systems.
O can describe an event in his O-spacetime coordinate $(t,x,y,z)$,
and P can describe the same event in his P-spacetime coordinate $(t',x',y',z')$.

An event happens at O-spacetime point P iff
O would instantaneously observe the event if he were at P.
If a light is fired from $(t,x,y,z)$ towards O,
then he will detect it at $(t+\sqrt{x^2+y^2+z^2}/c,0,0,0)$.
The set of points that are O-simultaneous at O-time $t$ is $\{(t,x,y,z) ~|~ x,y,z\in\mathbb{R}\}$.

Suppose that M has a ruler.
One tip, A, is at M.
The other tip, B, is at $\vec{x}$.
Event C: At M-time $t_0$, M fires a light from A.
Event D: At M-time $t_1$, the light hits B and reflects.
Event E: At M-time $t_2$, the reflection arrives at A.
The M-length of the ruler can be found from $\norm{\vec{x}} = c~(t_2-t_0)/2$.

Suppose that O sees M with constant velocity $\vec{v}$.

% http://www.pbs.org/wgbh/nova/blogs/physics/2014/04/how-many-dimensions-does-the-universe-really-have/

If something travels in O-spacetime from $(t,x,y,z)$ to $(t+dt,x+dx,y+dy,z+dz)$,
then its velocity can be found as follows:
\[
(dx)^2 + (dy)^2 + (dz)^2 = v^2~(dt)^2.
\]
If that thing is light then $v=c$.

The light-distance between two points in spacetime:
\[
(ds)^2 = (dx)^2 + (dy)^2 + (dz)^2 - c^2~(dt)^2.
\]

An observer exists as a point in space.
Given a point, he can measure his distance to it.
Given two points, he can measure his distance to each;
he can measure the distance between them;
he can measure the angle formed by the points through him;
he can determine if they lie in a line;
he can calculate the area enclosed by those points and him.

% European Journal of Physics
% Relativity, H. Bondi
% http://iopscience.iop.org/article/10.1088/0034-4885/22/1/304
% Nothing but relativity, redux
% http://iopscience.iop.org/article/10.1088/0143-0807/28/6/011/meta
% Lorentz transformations with arbitrary line of motion
% http://iopscience.iop.org/article/10.1088/0143-0807/28/2/004

% The principle of relativity and the indeterminacy of special relativity
% http://iopscience.iop.org/article/10.1088/0143-0807/29/1/004

\footnote{\url{https://en.wikipedia.org/wiki/Orbital_decay}}%
\footnote{\url{https://en.wikipedia.org/wiki/Gravitational_wave}}%
\footnote{\url{https://en.wikipedia.org/wiki/Two-body_problem_in_general_relativity}}

\footnote{\url{https://en.wikipedia.org/wiki/Newtonian_motivations_for_general_relativity}}

Somatogravic illusion
\footnote{\url{http://aviationknowledge.wikidot.com/aviation:somatogravic-illusion}}

Brans-Dicke theory

\footnote{\url{https://en.wikipedia.org/wiki/Hafele\%E2\%80\%93Keating_experiment}}%
\footnote{\url{https://en.wikipedia.org/wiki/Ives\%E2\%80\%93Stilwell_experiment}}%
\footnote{\url{https://en.wikipedia.org/wiki/Kennedy\%E2\%80\%93Thorndike_experiment}}


% body
\section{Results\label{sec:results}}
We now demonstrate the accuracy and performance of \qbkix to evaluate singular/near-\linebreak singular layer potentials on various complex geometries to solve the integral equation in \cref{eq:int-eq} and evaluate the solution as defined in \cref{eq:double_layer}.

\subsection{Classical convergence with patch refinement}
We will first demonstrate the numerical convergence behavior of \qbkix.
As discussed in \cite[Section 3.1]{KBGN}, approximation-based schemes such as \qbkix do not converge classically but do so up to a controlled precision if $r$ and $R$ scale with proportional to the patch size.
In order to observe classical convergence as we refine $\Pcoarse$, we must allow $R$ and $r$ to decrease slower than $O(L)$, such as with rate $O(\sqrt{L})$.
In this section, we choose the \qbkix parameters $a$ and $b$ proportional to $1/\sqrt{L}$ to achieve this and demonstrate numerical convergence with refinement of $L$.

In our examples, we use analytic solutions to \cref{eq:pde} obtained as sums of point charge functions of the form
\begin{equation}
  u_c(\vx) = \sum_{i=1}^m G(\vx,\vy_i)\psi_i
  \label{eq:point-charge-solution}
\end{equation}
%are solutions to \cref{eq:pde} by construction,
where the charge locations $\vy_i$ with strengths $\psi_i$ are outside of $\Omega$.
To construct specific solutions, we sample a sphere of radius one with point charges, as shown in \Cref{fig:greens-id-test-cases,fig:solver-conv-test-cases}.
We choose charge strengths $\psi_i$ randomly from $[0,1]^d$, where $d=1$ for Laplace problems and $d=3$ for Stokes and elasticity problems.

We use the multipole order  $m=20$ with $5000$ points per leaf box for the  kernel-independent \fmm.
This ensures that the \fmm error does not dominate;  sufficiently large number of points per leaf box is needed to minimize the additional error due to tree depth.
We choose a high quadrature order $q=20$, or 400 quadrature points per patch in $\Pcoarse$, relative to overall convergence order to satisfy the assumption in \cref{sec:adaptive_upsampling}.
We also use two levels of uniform upsampling to demonstrate convergence.

\subsubsection{Green's Identity}
\begin{figure}[!htb]
  \centering
  \begin{minipage}{.5\textwidth}
      \centering
    \includegraphics[width=\linewidth]{figs/cube_convergence_setup}
  \end{minipage}\hfill
  \begin{minipage}{.5\textwidth}
      \centering
    \includegraphics[width=\linewidth]{figs/newtorus_convergence_setup}
  \end{minipage}\hfill
  \mcaption{fig:greens-id-test-cases}{Geometry and singularities used for Green's Identity convergence tests.}{
  Shown are polynomial patches defining boundary geometry (black lines) and point singularities
  placed on the surface on a sphere of radius one.
  Singularity strengths are randomly selected values in $[0,1]$; shown is the strength intensity for Laplace problems, which varies from blue to red.
  We use 96 20th-order polynomial patches for the spheroid (left) and 32 cubic patches for the torus (right).
}
\end{figure}

\begin{table}[!htb]
\centering
\small
\setlength\tabcolsep{4pt}
\resizebox{\textwidth}{!}{%
\begin{tabular}{lllllll}
\toprule
{}Geometry & \pde &\multicolumn{4}{c}{Relative $\ell^\infty$ error (Number of patches)} & EOC\\
\midrule
Spheroid                                    & Laplace         &  $1.06\times 10^{-4}$ (96) &  $4.78\times 10^{-6}$ (384) &  $9.14\times 10^{-8}$ (1536) &  $4.35\times 10^{-9}$ (6144) & 4.77\\
(\cref{fig:greens-id-test-cases}-left)  & Elasticity      &  $1.68\times 10^{-3}$ (96) &  $6.94\times 10^{-5}$ (384) &  $1.53\times 10^{-6}$ (1536) &  $1.33\times 10^{-8}$ (6144) & 5.74\\
                                        & Stokes          &  $1.92\times 10^{-3}$ (96) &  $7.95\times 10^{-5}$ (384) &  $1.74\times 10^{-6}$ (1536) &  $1.53\times 10^{-8}$ (6144) & 5.72 \\
 \midrule
Torus                                         & Laplace         &  $2.05\times 10^{-3}$ (32) &  $7.52\times 10^{-5}$ (128) &   $3.79\times 10^{-6}$ (512) &  $8.48\times 10^{-8}$ (2048) & 5.45\\
 (\cref{fig:greens-id-test-cases}-right)      & Elasticity      &  $4.38\times 10^{-2}$ (32) &  $1.17\times 10^{-3}$ (128) &   $5.08\times 10^{-5}$ (512) &  $1.42\times 10^{-6}$ (2048) & 5.09\\
                                              & Stokes          &  $5.03\times 10^{-2}$ (32) &  $1.33\times 10^{-3}$ (128) &   $5.81\times 10^{-5}$ (512) &  $1.65\times 10^{-6}$ (2048) & 5.09\\
\bottomrule
\end{tabular}
}
\mcaption{table:greens-id-data}{$\ell^\infty$ Relative error in Green's Identity versus number of patches}{
  The solution to \cref{eq:pde} due to a known function $u_c$, shown in \cref{fig:greens-id-test-cases} is computed via Green's Identity.
  We evaluate the single- and double-layer potentials with \qbkix due to the Dirichlet and Neumann boundary data and compare against the known value of $u_c$ on the boundary.
  Each column is the result of an additional level of uniform quadrisection of the patches in $\Pcoarse$.
  The final column (EOC) is the estimated convergence order, computed via least-squares log-log fit of the error as a function of max patch size.
}
\end{table}

We report the accuracy of the \qbkix evaluation scheme in \cref{table:greens-id-data}, where we verify Green's Identity for a random known function $u_c$ in \cref{eq:point-charge-solution}.
We evaluate the Dirichlet and Neumann boundary data due to $u_c$ at the discretization points of $\Gammah$ and use one-sided \qbkix to evaluate the corresponding single- and double-layer potentials at the same discretization points.
With each column of \cref{table:greens-id-data}, we subdivide $\Pcoarse$ to more accurately resolve the boundary condition.
The error shown in \cref{table:greens-id-data} is the $\ell^\infty$-relative error in the solution value
\begin{equation}
  \frac{\left\|\hat{S}\left[\frac{\partial u_c}{\partial \vn}\right](\vx) - \hat{D} \left[ u_c \right](\vx) - u_c(\vx)\right\|_\infty}{\|u_c\|_\infty},
\end{equation}
where $\hat{S}$ and $\hat{D}$ are the single- and double-layer singular integral operators discretized and evaluated with \qbkix.
In these tests, we choose $p=6$, $r=.004\sqrt{L}$ ($a=.004/\sqrt{L}$) and $R=.03\sqrt{L}$ ($b=.03/\sqrt{L}$).
We observe roughly $5$th order convergence on both the spheroid and torus test geometries in \cref{fig:greens-id-test-cases} for each of the tested \pde's.
In \cref{table:greens-id-perf-data}, we present the number of target points evaluated per second per core with one-sided \qbkix.
We see that performance is best for Laplace and worst for elasticity problems, as expected.
\begin{table}[!htb]
\centering
\small
\setlength\tabcolsep{8pt}
\begin{tabular}{llllll}
\toprule
{}Geometry & \pde &\multicolumn{4}{c}{Target points/second/core}\\
\midrule
Spheroid                                    & Laplace         &  $3684$ &  $5438$ &  $5077$ &  $5629$ \\
(\cref{fig:greens-id-test-cases}-left)  & Elasticity      &  $1325$ &  $1731$ &  $1687$ &  $1790$ \\
                                        & Stokes          &  $1635$ &  $2075$ &  $2016$ &  $2120$ \\
 \midrule
Torus                                         & Laplace         &  $2729$  &  $3373$ &   $4564$  &  $5477$ \\
 (\cref{fig:greens-id-test-cases}-right)      & Elasticity      &  $984$   &  $1171$ &   $1347$  &  $1502$ \\
                                              & Stokes          &  $1134$  &  $1331$ &   $1609$  &  $1727$ \\
\bottomrule
\end{tabular}
\mcaption{table:greens-id-perf-data}{Performance of singular evaluation in Green's Identity}{
    For each test in \cref{table:greens-id-data}, we report the number of target points evaluated with one-sided \qbkix per second per core.
}
\end{table}

\subsubsection{Solution via \gmres}

\begin{figure}[!htb]
  \centering
  \hfill
  \begin{minipage}{.5\textwidth}
      \centering
    \includegraphics[width=\linewidth]{figs/pipe_convergence_setup}
  \end{minipage}\hfill
  \begin{minipage}{.5\textwidth}
      \centering
    \includegraphics[width=\linewidth]{figs/ttorus2_convergence_setup}
  \end{minipage}\hfill
    \mcaption{fig:solver-conv-test-cases}{Geometry and singularities used for solver convergence tests.}{ Figures are similar to \cref{fig:greens-id-test-cases}, but displaying geometries for testing the convergence of \qbkix within a \gmres solver.
  We use 30 16th-order polynomial patches for the pipe (left) and 50 20th-order patches for the genus two surface (right).
  Note the proximity of the singularities to the domain of the genus two surface; the nearest singularity is less than $.05L$ from $\Gammah$.
}
\end{figure}

\begin{table}
\centering
\small
\setlength\tabcolsep{4pt}
\resizebox{\textwidth}{!}{%
\begin{tabular}{lllllll}
\toprule
{}Geometry & \pde &\multicolumn{4}{c}{Relative $\ell^\infty$ error (Number of patches)} & EOC\\
\midrule
Spheroid (\cref{fig:greens-id-test-cases}-left) & Laplace   &  $2.70\times 10^{-6 }$ (96) &  $1.92\times 10^{-7 }$ (384) &  $4.47\times 10^{-9 }$ (1536) &  $5.13\times 10^{-11 }$ (6144) & 5.35 \\
   \midrule
Pipe                                       & Laplace       &  $5.99\times 10^{-4 }$ (30) &  $3.03\times 10^{-5 }$ (120) &   $6.68\times 10^{-7 }$ (480) &  $2.27\times 10^{-8 }$ (1920) & 5.92\\
(\cref{fig:solver-conv-test-cases}-left)   & Elasticity    &  $7.17\times 10^{-2 }$ (30) &  $3.57\times 10^{-3 }$ (120) &   $8.90\times 10^{-5 }$ (480) &  $4.14\times 10^{-6 }$ (1920) & 5.45\\
                                           & Stokes        &  $8.53\times 10^{-2 }$ (30) &  $4.12\times 10^{-3 }$ (120) &   $1.03\times 10^{-4 }$ (480) &  $4.73\times 10^{-6 }$ (1920) & 5.43\\
   \midrule
Genus 2                                     & Laplace     &  $4.00\times 10^{-2 }$ (50) &  $1.25\times 10^{-4 }$ (200) &   $1.54\times 10^{-6 }$ (800) &  $5.73\times 10^{-10 }$ (3200) & 8.76 \\
(\cref{fig:solver-conv-test-cases}-right)   & Elasticity  &  $9.20\times 10^{-2 }$ (50) &  $1.05\times 10^{-3 }$ (200) &   $1.00\times 10^{-5 }$ (800) &  $9.44\times 10^{-8 }$ (3200) & 6.89\\
                                            & Stokes      &  $1.03\times 10^{-1 }$ (50) &  $1.18\times 10^{-3 }$ (200) &   $1.15\times 10^{-5 }$ (800) &  $1.03\times 10^{-7}$ (3200)& 6.88\\
\bottomrule
\end{tabular}
}
\mcaption{table:solver-data}{$\ell^\infty$ Relative error in \gmres solve and solution evaluation versus number of patches}{
  We solve \cref{eq:pde} by discretizing and evaluating the layer potential in the integral equation in \cref{eq:int-eq} as described in \cref{sec:singular-eval}.
  We use two-sided \qbkix inside of \gmres to solve for $\phi$, then evaluate \cref{eq:double_layer_disc} with one-sided \qbkix at a new set of points on $\Gammah$.
  Each column is the result of an additional level of uniform quadrisection of the patches in $\Pcoarse$.
  The final column (EOC) is the estimated convergence order, computed via least-squares log-log fit of the error as a function of max patch size.
}
\end{table}

\begin{table}[!htb]
\centering
\small
\setlength\tabcolsep{8pt}
\begin{tabular}{llllll}
\toprule
{}Geometry & \pde &\multicolumn{4}{c}{Target points/second/core}\\
\midrule
%Cube                                    & Laplace         &  $2905$ &  $4124$ &  $4059$ &  $3979$ \\
Spheroid                                    & Laplace         &  $2737$ &  $3149$ &  $2846$ &  $2950$ \\
\midrule
%Pipe                                    & Laplace         &  $1894$ &  $3771$ &  $3757$ &  $4186$ \\
%(\cref{fig:greens-id-test-cases}-left)  & Elasticity      &  $361$  &  $451$ &   $459$  &  $480$  \\
%                                        & Stokes          &  $379$  &  $506$ &   $513$  &  $526$  \\
Pipe                                    & Laplace         &  $3046$ &  $2178$ &   $2832$  &  $2982$ \\
(\cref{fig:greens-id-test-cases}-left)  & Elasticity      &  $991$  &  $993$  &   $1189$  &  $1261$  \\
                                        & Stokes          &  $1048$ &  $1140$ &   $1335$  &  $1422$  \\
 \midrule
%Genus 2                                       & Laplace         &  $2542$  &  $3747$ &   $3895$  &  $4227$ \\
% (\cref{fig:greens-id-test-cases}-right)      & Elasticity      &  $350$  &  $531$ &   $553$  &  $564$ \\
%                                              & Stokes          &  $398$  & $587$ &   $638$  &  $X$ \\
Genus 2                                       & Laplace         &  $1862$ &  $2886$ &  $3122$  &  $2879$ \\
 (\cref{fig:greens-id-test-cases}-right)      & Elasticity      &  $729$  &  $1125$ &  $1255$  &  $1295$ \\
                                              & Stokes          &  $929$  &  $1304$ &  $1450$  &  $1504$ \\
\bottomrule
\end{tabular}
\mcaption{table:solver-perf-data}{Performance of singular evaluation in \gmres matrix-vector multiply}{
    For each test in \cref{table:solver-data}, we report the number of target points per second per core evaluated with two-sided \qbkix in a single \gmres matrix-vector multiplication.
}
\end{table}
We report the accuracy of the \qbkix scheme when used to solve \cref{eq:pde} via the integral equation in \cref{eq:int-eq}.
Two-sided \qbkix is used in the matrix-vector multiply inside \gmres to solve \cref{eq:int-eq} for the values of the density $\phi$ at the discretization points.
Then one-sided \qbkix is used to evaluate \cref{eq:double_layer_disc} at a slightly coarser discretization.
Since \gmres minimizes the residual at the original discretization of \cref{eq:int-eq}, this final step prevents an artificially accurate solution by changing discretizations.
\cref{table:solver-data} lists the $\ell^\infty$ relative error values for the total solve and evaluation steps using \cref{sec:singular-eval} as we refine $\Pcoarse$ by subdivision as in the previous section.
In these tests, we choose $p=6$, $r= .005\sqrt{L}$ ($a = .005/\sqrt{L}$), and  $R= .03\sqrt{L}$ ($b = .03/\sqrt{L}$).
As for previous examples, we observe at least $5$th order convergence on all tested geometries in \cref{fig:solver-conv-test-cases} and \cref{fig:greens-id-test-cases}-left and all \pde's.
We include the spheroid example as an additional demonstration of a high accuracy solution via \gmres with our approach.
We report the number of target points evaluated per second per core with two-sided \qbkix in \cref{table:solver-perf-data}.
The results are similar to \cref{table:greens-id-perf-data}; the slower performance is because evaluation via two-sided \qbkix is more expensive than one-sided \qbkix.
\subsection{Comparison with \cite{YBZ}\label{sec:results-compare}}
In this section,  we compare our method to \cite{YBZ}, a previously proposed high-order, kernel-independent singular quadrature method in \threed for complex geometries. These characteristics are similar to  \qbkix shares these characteristics. \cref{app:results-compare} presents additional comparisons.

%To understand the performance of these two methods and see the implications of this complexity difference in practice, we now compare the performance of \qbkix with that of \cite{YBZ} on several concrete numerical examples.

The metric we are interested is \textit{cost for a given relative error}.
Assuming the surface discretization is $O(N)$, we measure the cost of a method as its total wall time during execution $T$ divided by the total wall time of an \fmm evaluation on the same $O(N)$ discretization, $T_\lbl{FMM}$.
By normalizing by the \fmm evaluation cost, we minimize the dependence of the cost on machine- and implementation-dependent machine-dependent parameters.
%, such as clock speed, cache size, performance optimizations, etc.

We run the tests in this section on the spheroid geometry shown in \cref{fig:greens-id-test-cases}-left.
We focus on the singular quadrature scheme of \cite{YBZ}.
The near-singular quadrature of \cite{YBZ} is algorithmically similar to \qbkix, but since an expensive singular quadrature rule is used as a part of near-singular evaluation, it has a higher total cost.
As a result, the accuracy and cost of near-singular evaluation of \cite{YBZ} is bounded by the accuracy and cost of the singular integration scheme.

To compare the full \qbkix method with \cite{YBZ}, we fit polynomial patches to the $C^\infty$ surface of \cite{ying2004simple}, denoted $\Gamma_b$, to produce $\Gammah$ during the first step of \cref{sec:admissible_algo}.
We apply the remaining geometry preprocessing algorithms of \cref{sec:admissible_algo} to $\Gammah$ to produce $\Pcoarse$.
After producing $\Pfine$ with two levels of uniform upsampling, we solve \cref{eq:int-eq} with two-sided \qbkix on $\Gammah$ and evaluate the solution on the boundary with one-sided \qbkix.
We then solve for the solution to \cref{eq:int-eq} on $\Gamma_b$ using \cite{YBZ}.

For each of the tests in this section, we choose some initial spacing parameter
$h_0$ to discretize the surface of \cite{ying2004simple}, as in \cite{YBZ}, and use the $16\times$ upsampled grid and floating partition of unity radius proportional to $O(\sqrt{h})$, as in the original work.
We apply \qbkix to $\Gammah$ and the scheme of \cite{YBZ} to $\Gamma_b$ with spacing $h_0/2^i$, for $i=1,\hdots 4$.

As in the previous section, we choose the parameters $r$ and $R$ of \qbkix to be $O(\sqrt{L})$.
For both quadrature methods, we use a multipole order of $16$ for \pvfmm with at most 250 points in each leaf box.
\begin{figure}[!htb]
  \centering
    \makebox[\textwidth][c]{ \includegraphics[width=1.1\textwidth]{figs/comparison_face_map_vs_blendsurf_cube_laplace_timing.pdf} }
    \makebox[\textwidth][c]{ \includegraphics[width=1.1\textwidth]{figs/comparison_face_map_vs_blendsurf_cube_navier_timing.pdf} }
%  \hfill
%  \begin{minipage}{\textwidth}
%    \includegraphics[width=\linewidth]{figs/comparison_face_map_vs_blendsurf_cube_laplace_timing.pdf}
%  \end{minipage}\hfill
%  \begin{minipage}{\textwidth}
%    \includegraphics[width=\linewidth]{figs/comparison_face_map_vs_blendsurf_cube_navier_timing.pdf}
%  \end{minipage}\hfill
    \mcaption{fig:compare-solve-surface}{Comparison of \qbkix on polynomial patches (HH) versus \cite{YBZ} on the surface representation of \cite{ying2004simple} (POU) solving via \gmres for $u_c$}{
    Laplace (top) and elasticity (bottom) problems solved on the spheroid shown in \cref{fig:greens-id-test-cases}.
From left to right, we plot the total cost of each scheme, the cost of each subroutine for \qbkix (blue) and the singular quadrature scheme of \cite{YBZ} (red), and the relative error as a function of $h$.
    We plot error convergence of \cite{YBZ} as a function of $h$ and \qbkix as a function of $L$, due to the distinct discretizations.
    For \qbkix parameters, we choose $r=.013\sqrt{L}$, $R=.075\sqrt{L}$ for the Laplace problem; for the elasticity problem, we choose $r=.013\sqrt{L}$, $R=.08\sqrt{L}$. We choose $p=6$ and $q=15$ for both problems.
    For \cite{YBZ} the spacing is $h_0=.35$.
    Note that in the \qbkix timing breakdown, since the \fmm time is dominant, the \fmm cost lies directly on top of the total cost.
  }
\end{figure}
The results are shown in \cref{fig:compare-solve-surface}.
From left to right, each plot details the total cost of each scheme, the cost of each subroutine for \qbkix (denoted \abbrev{HH}) and the singular quadrature scheme of \cite{YBZ} (denoted \abbrev{POU}), and the relative error as a function of $h$ and $L$, respectively,
for all refinement levels.
%Each data point in the plots, from right to left, is the result of $4\times $ finer sampling of the surfaces.
We plot the cost of both schemes the cost of each algorithmic step as a function of their computed relative error.
In each figure, we present results for a Laplace problem (top) and an elasticity problem (bottom). % to highlight the difference in performance between scalar and vector kernels.

In \cref{fig:compare-solve-surface}, as expected, we observe a  higher  convergence rate for \qbkix compared to \cite{YBZ}.
\cite{YBZ} outperforms \qbkix in terms of cost for all tested discretizations.
%\DZ{For vector problems, the cost of additional \qbkix evaluations
%for the problem size considered outweighs the savings from not using an asymptotically
%more expensive singular quadrature.}
% This is due to the greater cost of a vector \fmm evaluation compared to a scalar one: the $m+p$  \fmm evaluation of \cite{YBZ} can be accelerated more efficiently with the method's small dense linear algebra computations.
 We observe that the \fmm evaluation in \cref{fig:compare-solve-surface} accounts for at least 95\% of the \qbkix cost.
This means that a local singular quadrature method (based on corrections to an \fmm evaluation, \cref{sec:related_work}) of \textit{worse} complexity can beat a global method, simply by virtue of reducing the \fmm size.
%Moreover, our implementation of \cite{YBZ} is not highly optimized, so we can expect a well-engineered \pou singular quadrature implementation such as \cite{malhotra2019taylor} to widen this gap.
By noting the large difference between the \qbkix \fmm cost and the \qbkix density interpolation, we can reasonably infer that a local \qbkix scheme should narrow this  performance gap and outperform \cite{YBZ} for larger problems, assuming that switching to a local scheme does not dramatically affect error convergence.

\edit{}{
  \emph{Remark: } A recent novel solver using a local quadrature approach, called \fmmbie, }\cite{greengard2021fast}\edit{}{, achieves this performance improvement using an adaptive refinement approach.
This solver is highly optimized and is $O(N)$ complexity, achieving an order of magnitude speed up over \qbkix.
This further supports our conclusion that a local quadrature approach should rapidly outpace a global one.
It remains to be seen if a local version \qbkix will outperform \fmmbie and we leave this to future work.
}
%\qbkix is more efficient in the high-accuracy regime for Laplace problems, but \cite{YBZ} is more efficient for low-accuracy Laplace and elasticity problems.
%However, main difference from the previous section is that the crossover point in performance appears to be larger; \qbkix becomes more efficient than \cite{YBZ} around $10^{-5}$ and the gap between \qbkix and \cite{YBZ} for elasticity is less dramatic at $10^{-8}$.
%We attribute this improvement to the more efficient Clenshaw-Curtis discretization of \qbkix compared to the overlapping trapezoidal discretization of \cite{YBZ}.
%This is further supporting evidence that a local \qbkix implementation should surpass \cite{YBZ}.

\subsection{Requested target precision vs. computed accuracy}
\begin{figure}[!htb]
\begin{tikzpicture}
    \begin{loglogaxis}[
        xlabel=$\err{target}$,
        ylabel= $\infty$-norm relative error,
        ylabel near ticks,
        xlabel near ticks,
        label style={font=\scriptsize},
        tick label style={font=\scriptsize},
        width=.333\linewidth%7cm,height=3cm
    ]
    \addplot[smooth,mark=*,blue] plot coordinates {
        (1e-4,0.0003143683435301948)
        (1e-5,6.031924968205908e-05)
        (1e-6,4.103514547039301e-06)
        (1e-7,6.614064613404895e-07)
        (1e-8,1.122384348756594e-07)
    };
        \addplot[domain=1e-8:1e-4,dotted,thick]{x};

    \end{loglogaxis}
    \end{tikzpicture}
    \begin{tikzpicture}
    \begin{semilogxaxis}[
        xlabel=$\err{target}$,
        ylabel= Target points/second/core,
        ylabel near ticks,
        xlabel near ticks,
        label style={font=\scriptsize},
        tick label style={font=\scriptsize},
        width=.333\linewidth%7cm,height=3cm
    ]
    \addplot[smooth,mark=*,blue] plot coordinates {
        (1e-4,2077)
        (1e-5,1620)
        (1e-6,772)
        (1e-7,400)
        (1e-8,222)
    };
    \end{semilogxaxis}
    \end{tikzpicture}
    \begin{tikzpicture}
    \begin{loglogaxis}[
        xlabel=$\err{target}$,
        ylabel= Number of patches,
        ylabel near ticks,
        xlabel near ticks,
        label style={font=\scriptsize},
        tick label style={font=\scriptsize},
        legend style={font=\tiny},
         legend image post style={scale=0.5},
        width=.333\linewidth%7cm,height=3cm
    ]
    \addplot[smooth,mark=*,blue] plot coordinates {
        (1e-4,128)
        (1e-5,128)
        (1e-6,128)
        (1e-7,128)
        (1e-8,128)
    };
    \addlegendentry{$|\Pcoarse|$}
    \addplot[smooth,mark=*,red] plot coordinates {
        (1e-4,5408)
        (1e-5,8288)
        (1e-6,28256)
        (1e-7,60032)
        (1e-8,113936)
    };
    \addlegendentry{$|\Pfine|$}
    \end{loglogaxis}
    \end{tikzpicture}
        \mcaption{fig:full-algo-perf}{Performance of full algorithm}{
            Left: $\infty$-norm relative error in singular integral vs requested target accuracy (blue).
        The dotted line is the ideal behavior $y=x$.
        Middle: Performance in terms of target points evaluated per second per core with \qbkix.
        Right: Number of patches in $\Pcoarse$ and $\Pfine$ computed by the preprocessing algorithms.}
\end{figure}

In this section, we study the performance of the full algorithm outlined in \cref{sec:algo}.
We test \qbkix on the torus domain shown in \cref{fig:greens-id-test-cases}-right.
We choose a reference solution of the form of \cref{eq:point-charge-solution} with a single point charge located at the origin, in the middle of the hole of the torus.
We solve the integral equation with two-sided \qbkix and evaluate the singular integral on a distinct discretization with one-sided \qbkix.
We choose $q=20$, $p=6$ and $a=b/6$.
We select various values for $\err{target}$ using the plot in \cref{fig:extrap-err-p6} to choose $b$ to ensure sufficiently accurate extrapolation.
We plot the results of our tests in \cref{fig:full-algo-perf}.

We see in \cref{fig:full-algo-perf}-left that we are consistently close to the requested target precision.
We see a decline in target points per second per core as accuracy increases in \cref{fig:full-algo-perf}-middle.
This is explained by \cref{fig:full-algo-perf}-right, which shows an increase in the size $\Pfine$ as $\Pcoarse$ remains a fixed size.
The initial 128 patches in $\Pcoarse$ are enough to resolve the boundary condition and $\Gamma$, but we need greater quadrature accuracy for lower values of $\err{target}$ .
Decreasing the number of points in passed to the \fmm, i.e., decreasing the size of $\Pfine$, is the main way to improve performance of our method.
This is further indication that a local version of \qbkix will outperform a global approach.

\subsection{Full algorithm on interlocking torii\label{sec:results-torii}}
We now demonstrate the full algorithm pipeline on an exterior Laplace problem, whose boundary is defined by four interlocking torii shown in \cref{fig:torii}.
The domain boundary is contained in the box $[-3.8, 2.4] \times [-1.1, 1.1] \times [-1,1]$.
The shortest distance between two adjacent torii is less than 10\% of a polynomial patch length defining the boundary.
We again use a boundary condition of the form \cref{eq:point-charge-solution} with a single point charge located at $(0,.03,.875)$, inside the upper half of the second torus from the right in \cref{fig:torii}.
This problem is challenging due to the nearly touching geometry of the torii, along with the singularity placed close to the boundary.
We run the admissibility and adaptive upsampling algorithms outlined in \cref{sec:algo}, solve \cref{eq:int-eq} using two-sided \qbkix, and evaluate the solution on the boundary using one-sided \qbkix.
The absolute error in the $\infty$-norm of the singular evaluation is plotted on the boundary surface.

\begin{figure}[!htb]
  \centering
  \hfill
  \begin{minipage}{.65\textwidth}
    \includegraphics[width=\linewidth]{figs/interlocking_torus_error.png}
  \end{minipage}\hfill
  \begin{minipage}{.35\textwidth}
    \includegraphics[width=\linewidth]{figs/interlocking_torus_error_cross_section.png}
  \end{minipage}\hfill
  \mcaption{fig:torii}{Absolute error of \gmres solve via \qbkix on interlocking torii}{Left: The admissible set of 1128 patches in $\Pcoarse$ used to solve \cref{eq:int-eq} is shown (black lines denote patch boundaries).
  The point charge generated the boundary condition is located within the second torus from the right.
    Right: a cross-section of the torii geometry through the $xz$-plane, showing the second torus from the right and the location of the singularity (green point).
}
\end{figure}
Using $a=.1$, $b=.025$, $p=6$ and $q=20$, we achieve a maximum pointwise error of $1.29\times 10^{-5}$.
\gmres was able to reduce the residual by a factor of $10^{-13}$ over 109 iterations.
There are 288768 quadrature points in the coarse discretization, 18235392 quadrature points in the fine discretization, and 3465216 check points used in the two-sided \qbkix evaluation inside \gmres.
We evaluate the solved density at 451200 points on the boundary with one-sided \qbkix to produce the render in \cref{fig:torii}.
On a machine with two Intel Xeon E-2690v2 3.0GHz \abbrev{CPU}'s, each with 10 cores, and 100 \abbrev{GB} of \abbrev{RAM},
the \gmres solve and interior evaluation required 5.7 hours and can evaluate the singular integral at a rate of 1709 target points per second per core.

\subsection{Solution on complex geometry\label{sec:results-blood-vessel}}

\begin{figure}[!htb]
  \centering
  \hfill
  \begin{minipage}{.7\textwidth}
    \includegraphics[width=\linewidth]{figs/largest_vessel_section.png}
  \end{minipage}\hfill
  \mcaption{fig:vessel}{Absolute error of \gmres solve via \qbkix on complex blood vessel geometry used in \cite{lu2019scalable}}{The blood vessel uses 40,960 8th order polynomial patches (black edges denote patch boundaries). The geometry is admissible by construction.
    The point charge is located on left side of the figure (green)}
\end{figure}

We have demonstrated in \cite{lu2019scalable} a parallel implementation of \cref{sec:singular-eval}, applied to simulating red blood cell flows.
The surface geometry of the blood vessel shown in \cref{fig:vessel} is complex, with rapidly varying curvatures and geometric distortions due to singular vertices in the surface mesh.
Since the surface is admissible, we are able to apply parallel \qbkix directly without geometric preprocessing to solve an interior Dirichlet Stokes problem.
We use $a=.125$, $b=.125$, $p=6$ and $q=16$ as simulation parameters.

Using 32 machines each with twenty 2.6 Ghz cores with 100\abbrev{GB} of \abbrev{RAM}, we achieve a maximum pointwise error of $3\times 10^{-6}$ when solving a Stokes problem with constant density.
We then place a random vector point charge two patch lengths away (relative to the patches in $\Pcoarse$) from the domain boundary (on the left side of \cref{fig:vessel}, solve \cref{eq:int-eq} using two-sided \qbkix, and evaluate the solution on the boundary using one-sided \qbkix.
The absolute error in the $\infty$-norm of the singular evaluation is plotted on the boundary surface.
There are 10,485,760 quadrature points in the coarse discretization, 167,772,160 quadrature points in the fine discretization, and 125,829,120 check points used in the two-sided \qbkix evaluation inside \gmres.
We evaluate the solved density at 209,715,200 points on the boundary with one-sided \qbkix to produce the render in \cref{fig:torii}.
We achieve a maximum pointwise error of $1.8\times 10^{-2}$ and can evaluate the singular integral at rate of 3529 target points per second per core.
%The \gmres solve with two-sided \qbkix converged to \note[MJM]{X} in \note[MJM]{Y} iterations in \note[MJM]{Z} hours.