\section{Distance, Velocity, Acceleration}\label{sec:IntVel}
We recall a general principle that will later be applied to
distance-velocity-acceleration problems, among other things.  If $F(u)$ is
an anti-derivative of $f(u)$, then $\ds \int_a^bf(u)\,du=F(b)-F(a)$.  Suppose
that we want to let the upper limit of integration vary, i.e., we replace
$b$ by some variable $x$.  We think of $a$ as a fixed starting value $x_0$.
In this new notation the last equation (after adding $F(a)$ to both sides)
becomes:
$$
  F(x)=F(x_0)+\int_{x_0}^xf(u)\,du.
$$
Here $u$ is the variable of
integration, called a ``dummy variable,'' since it is not the variable in
the function $F(x)$.  In general, it is not a good idea to use the same
letter as a variable of integration and as a limit of integration.  That
is, $\ds \int_{x_0}^xf(x)dx$ is bad notation, and can lead to errors and
confusion.

An important application of this principle occurs when we are
interested in the position of an object at time $t$ (say, on the
$x$-axis) and we know its position at time $\ds t_0$.  Let $s(t)$ denote
the position of the object at time $t$ (its distance from a reference
point, such as the origin on the $x$-axis).  Then the net change in
position between $\ds t_0$ and $t$ is $\ds s(t)-s(t_0)$.  Since $s(t)$ is an
anti-derivative of the velocity function $v(t)$, we can write
$$
  s(t)=s(t_0)+\int_{t_0}^tv(u)du.
$$
Similarly, since the velocity is an anti-derivative of the acceleration
function $a(t)$, we have
$$
  v(t)=v(t_0)+\int_{t_0}^ta(u)du.
$$

\begin{example}{Constant Force}{ConstantForce}
Suppose an object is acted upon by a constant
force $F$.  Find $v(t)$ and $s(t)$.
\end{example}

\begin{solution}
By Newton's law $F=ma$, so the acceleration is
$F/m$, where $m$ is the mass of the object.  Then we first have
$$
  v(t)=v(t_0)+\int_{t_0}^t{F\over m}\,du=v_0+
  \left.{F\over m}u\right|_{t_0}^t=v_0+{F\over m}(t-t_0),
$$
using the usual convention $\ds v_0=v(t_0)$.
Then
\begin{eqnarray*}
  s(t)&=s(t_0)+\int_{t_0}^t\left(v_0+{F\over m}(u-t_0)\right)du=s_0+
  \left.(v_0u+{F\over2m}(u-t_0)^2)\right|_{t_0}^t\cr
      &=s_0+v_0(t-t_0)+{F\over2m}(t-t_0)^2.\cr
\end{eqnarray*}
For instance, when $F/m=-g$ is the constant of gravitational acceleration,
then this is the falling body formula (if we neglect air resistance)
familiar from elementary physics:
$$s_0+v_0(t-t_0)-{g\over2}(t-t_0)^2,$$
or in the common case that $\ds t_0=0$,
$$s_0+v_0t-{g\over2}t^2.$$
\end{solution}

Recall that the integral of the velocity function gives the \ifont{net} distance
traveled. If you want to know the \ifont{total} distance traveled,
you must find out where the velocity function
crosses the $t$-axis, integrate separately over the time intervals when
$v(t)$ is positive and when $v(t)$ is negative, and add up the absolute
values of the different integrals.  For example, if an object is thrown
straight upward at 19.6 m/sec, its velocity function is
$v(t)=-9.8t+19.6$, using $g=9.8$ m/sec for the force of gravity.
This is a straight line which is positive for $t<2$ and negative for $t>2$.
The net distance traveled in the first 4 seconds is thus
$$\int_0^4(-9.8t+19.6)dt=0,$$
 while the total distance traveled in the first
4 seconds is
$$
  \int_0^2(-9.8t+19.6)dt+\left|\int_2^4(-9.8t+19.6)dt\right|=19.6+|-19.6|=39.2
$$
meters, $19.6$ meters up and $19.6$ meters down.

\begin{example}{Net and Total Distance}{NetTotalDistance}
The acceleration of an object is given by $a(t)=\cos(\pi
t)$, and its velocity at time $t=0$ is $1/(2\pi)$.  Find both the net and the
total distance traveled in the first 1.5 seconds.
\end{example}

\begin{solution}
We compute
$$
  v(t)=v(0)+\int_0^t\cos(\pi u)du={1\over 2\pi}+\left.{1\over\pi}
  \sin(\pi u)\right|_0^t={1\over\pi}\bigl({1\over2}+\sin(\pi t)\bigr).
$$
The \ifont{net} distance traveled is then
\begin{eqnarray*}
  s(3/2)-s(0)&=&\int_0^{3/2}{1\over\pi}\left({1\over2}+\sin(\pi t)\right)\,dt\cr
  &=&\left.{1\over\pi}\left({t\over2}-{1\over\pi}\cos(\pi t)\right)
  \right|_0^{3/2}\cr
  &=&{3\over4\pi}+{1\over\pi^2}\approx 0.340 \hbox{ meters.}\cr
\end{eqnarray*}
To find the {\it total} distance traveled, we need to know when
$(0.5+\sin(\pi t))$ is positive and when it is negative.  This
function is 0 when $\sin(\pi t)$ is $-0.5$, i.e., when $\pi t=7\pi/6$,
$11\pi/6$, etc.  The value $\pi t=7\pi/6$, i.e., $t=7/6$, is the only
value in the range $0\le t\le 1.5$.  Since $v(t)>0$ for $t<7/6$ and
$v(t)<0$ for $t>7/6$, the total distance traveled is
$$ \int_0^{7/6}\ds{1\over \pi}\left({1\over2}+\sin(\pi t)\right)\,dt+
  \Bigl|\int_{7/6}^{3/2}
  {1\over \pi}\left({1\over2}+\sin(\pi t)\right)\,dt\Bigr|
$$
\begin{eqnarray*}
%& \ds \int_0^{7/6}\ds{1\over \pi}\left({1\over2}+\sin(\pi t)\right)\,dt+
%  \Bigl|\int_{7/6}^{3/2}
%  {1\over \pi}\left({1\over2}+\sin(\pi t)\right)\,dt\Bigr|\\
 ~\qquad~&=&\ds{1\over \pi}\left( {7\over 12}+{1\over \pi}\cos(7\pi/6)+{1\over
    \pi}\right)+
  {1\over \pi}\Bigl|{3\over 4}-{7\over 12}
  +{1\over \pi}\cos(7\pi/6)\Bigr|\\
  &=&\ds{1\over \pi}\left( {7\over 12}+{1\over \pi}{\sqrt3\over2}+{1\over
    \pi}\right)+
  {1\over \pi}\Bigl|{3\over 4}-{7\over 12}
  +{1\over \pi}{\sqrt3\over2}.\Bigr|\\
  &\approx& 0.409 \hbox{ meters.}
\end{eqnarray*}
\end{solution}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Opensolutionfile{solutions}[ex]
\section*{Exercises for Section \ref{sec:IntVel}}

\begin{enumialphparenastyle}

%%%%%%%%%%
\begin{ex}
 An object moves so that its velocity at time $t$ is
$v(t)=-9.8t+20$ m/s. Describe the motion of the object between $t=0$ and
$t=5$, find the total distance traveled by the object during that
time, and find the net distance traveled.
\begin{sol}
 It rises until $t=100/49$, then falls. The position of the
object at time $t$ is $\ds s(t)=-4.9t^2+20t+k$. The net distance traveled
is $-45/2$, that is, it ends up $45/2$ meters below where it started.
The total distance traveled is $6205/98$ meters.
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 An object moves so that its velocity at time $t$ is $v(t)=\sin t$.
Set up and evaluate a single definite integral to compute the
net distance traveled between $t=0$ and $t=2\pi$.
\begin{sol}
 $\ds\int_0^{2\pi}\sin t\,dt=0$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 An object moves so that its velocity at time $t$ is
$v(t)=1+2\sin t$ m/s. Find the net distance traveled by the object
between $t=0$ and $t=2\pi$, and find the total distance traveled
during the same period.
\begin{sol}
 net: $2\pi$, total: $\ds 2\pi/3+4\sqrt3$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 Consider the function $f(x)=(x+2)(x+1)(x-1)(x-2)$ on
$[-2,2]$. Find the total area between the curve and the $x$-axis
(measuring all area as positive).
\begin{sol}
 $8$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 Consider the function $\ds f(x)=x^2-3x+2$ on
$[0,4]$. Find the total area between the curve and the $x$-axis
(measuring all area as positive).
\begin{sol}
 $17/3$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 Evaluate the three integrals:
$$
  A=\int_0^3 (-x^2+9)\,dx\qquad B=\int_0^{4} (-x^2+9)\,dx\qquad
  C=\int_{4}^3 (-x^2+9)\,dx,
$$
and verify that $A=B+C$.
\begin{sol}
 $A=18$, $B=44/3$, $C=10/3$
\end{sol}
\end{ex}

\end{enumialphparenastyle}


\section{Discussion}

The two methods proposed by L. Sani and P. Hudzovic and two combinations thereof
were investigated and compared to one another.

The most accurate method -- in general -- turns out to be P. Hudzovic's transfer
function in conjunction with L. Sani's  characterisation  method  (by  measuring
$t_{10}$, $t_{50}$, $t_{90}$ instead of $T_u/T_g$). This  is true for all orders
of  $n$  and  this  is  true  for   noisy   and   non-noisy   input   functions.

Of course,  by performing a least-square curve fit, an even more accurate result
can be obtained.

One factor that was not  considered  is how many data points are required in the
lookup  curves  to yield accurate enough results. The simulations in this report
used  50  data  points. It would be worth investigating this further to see  how
higher resolution (or  lower  resolution)  lookup  curves affect the accuracy of
each method.

P.  Hudzovic's  characterisation method (by measuring $T_u/T_g$) isn't as robust
as  L.  Sani's   characterisation   method  (by  measuring  $t_{10}$,  $t_{50}$,
$t_{90}$),  especially  with  noisy  input data. This is primarily  due  to  the
derivative  that  must  be  computed  to   find   the   point   of   inflection.

L. Sani's method is definitely  the  easiest  to  implement  due  to  the simple
interpolation formulae and due to  the simplicity of finding $t_{10}$, $t_{50}$,
$t_{90}$. It also performs quite  fast  and has a low memory footprint (since it
doesn't require any lookup curves).  Unfortunately, it does perform the worst of
all methods.


\documentclass[12pt]{article}
\usepackage{geometry}
\geometry{margin=1in}
\geometry{a4paper}

\usepackage{textcomp}
\usepackage{booktabs}
\usepackage{array}
\usepackage{paralist}
\usepackage{verbatim}
\usepackage{subfigure}
\usepackage{graphicx,caption}
\usepackage{placeins}
\usepackage{lipsum}
\usepackage{xcolor}
\usepackage{dcolumn}
\usepackage{sectsty}
\allsectionsfont{\sffamily\mdseries\upshape}
\usepackage{gensymb,amsmath,mathtools,amssymb}
\usepackage{flafter}
%\usepackage{parskip}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{tocbibind}
\usepackage[toc,page]{appendix}
\captionsetup{width=\linewidth}
\usepackage{bm}
\usepackage{lscape}

\graphicspath{{./figs/}}

\title{First Order Optimal Sizing of Ascent Vehicles}
\author{Devansh Agrawal}
%\date{}

\begin{document}

\maketitle

\section{Problem Description}

In designing a ascent vehicle, it is important to start a design relatively close to the optimal solution. In this document, I optimize the thrust of a one dimensional rocket to maximise the apogee altitude. The parameters that are specified fall into the following categories:
\begin{itemize}
\item Environment parameters: $g, \rho(h)$
\item Design parameters: $m_0, m_p, c_d, A,c$\footnote{$m_0$ is the launch mass, $m_p$ is the propellant mass}
\item Control parameters: $F(t)$
\end{itemize}

For initial sizing, we make the following assumptions on the rocket dynamics:
\begin{itemize}
\item Earth is inertial, non-rotating, and the acceleration due to gravity is constant with altitude, $g = 9.81$~m/s$^2$
\item Earths atmosphere follows an exponential relationship, $\rho(h) = \rho_0 e^{-\beta h}$, where for the earth, $\rho_0 = 1.225$~kg/m$^3$, $\beta = 1/8.5$~km$^{-1}$
\item The rockets drag coefficient is constant, independent of the mach number\footnote{In general, this is not a good assumption, however, as we will see later, the maximum mach number of the rocket is to be kept below $M\sim0.7$. A numeric optimiser should be used later to refine the vehicle.}
\item The rockets specific impulse is a constant $I_{sp} = c g_0$, and does not depend on altitude.
\item The thrust curve is extremely simple. The rocket thrusts at a constant $F$~newtons for $t_b$~seconds. For this simplifying case, we do not need to include $t_b$ in our parameters since it is implicitly defined:
\begin{align}
I_t &= \int F dt = F t_b\\
\text{and } I_t &= \int -\dot{m} c dt  = m_p c\\
\therefore t_b &= \frac{m_p c}{F}
\end{align}
\end{itemize}

Hence, we will try to determine the optimum value of $F$ given all the other parameters.

\section{State space description, and non-dimensionalisation}

The dynamics of a 1-D rocket can be written as
\begin{align}
\dot{h} &=v \\
\dot{v} &=\frac{1}{m}(F(t)-D(v, h))-g \\
\dot{m} &=\frac{-F(t)}{c}
\end{align}

Directly integrating this is difficult, but we can do so numerically, using Mathematica. From their, the maximum height is readily determined. However there are 6 parameters that can be chosen in this problem, and the dependence due to 3 more. To simplify the analysis we introduce non-dimensional parameters. The reference quantities used are

\begin{itemize}
\item Mass: $m_0$
\item Acceleration: $g$
\item Speed: $c$
\end{itemize}

Therefore the following reference dimensions can be found:
\begin{itemize}
\item Force: $m_0 g$
\item Time: $c/g$
\item Length: $c^2/g$
\item Total Impulse: $1/(m_0 c)$
\end{itemize}

Using hats to denote the non-dimensionalised quantities, the state space equation can be written as

\begin{align}
\dot{\hat{h}} &=\hat{v} \\
\dot{\hat v} &=\frac{\hat F}{\hat m}  - \left( \frac{\rho c^2 c_d A}{2 m_0 g} \right) e^{- (\beta c^2/g) \hat h}  \frac{ \hat{v}^2}{\hat m}  - 1 \\
\dot{\hat m} &=-\hat F
\end{align}

Furthermore, the switching occurs at $t = t_b$. Interestingly, the non-dimensionalized total impulse is  directly related to the propellant mass fraction:
\begin{align}
\hat{I_t} &= \frac{I_t}{m_0 c} = \frac{F t_b}{m_0 c} = \frac{m_p c}{m_0 c} = \frac{m_p}{m_0}\\
\therefore \hat{t_b} &= \frac{I_t}{F} = \frac{m_p}{m_0} \frac{1}{\hat F}
\end{align}

Therefore, the important parameters are now immediately obvious, and can be interpreted as,

\begin{enumerate}
\item The thrust to initial weight ratio,
\begin{equation}
\hat F = \frac{F}{m_0 g}
\end{equation}

\item A drag parameter defined as,
\begin{equation}
x \equiv \frac{\frac{1}{2} \rho c^2 c_d A}{m_0 g}
\end{equation}
Note: This parameter is like the drag to weight ratio (except it uses $c$ as the velocity and $m_0$ as the mass)

\item Propellant mass fraction,
\begin{equation}
MR \equiv m_p/m_0
\end{equation}

\item Atmosphere parameter,
\begin{equation}
\hat \beta = \beta \frac{c^2}{g}
\end{equation}
which scales the atmosphere's height to the height we are interested in.
\end{enumerate}

Finally, the parameter to be optimised is the final altitude,

\begin{equation}
h_f = \hat h_f \frac{c^2}{g}
\end{equation}

Therefore, our 8 parameter space has reduced to a four parameter space, three if we assume the specific impulse of the rocket is fixed.

The typical range of these parameters, and a rough order of magnitude for a 10k solid rocket are

\begin{center}
   \begin{tabular}{@{} ccc@{}}
      \toprule
      Parameter & Typical value & Range\\
      \midrule
      $\hat F$ & 15 & $>1$\\
      $x$ & 60 & $>0$\\
      $MR$ & 0.15 & $0.3\sim0.9$\\
      $\hat \beta$ & 50 & $25 \sim 75$\\
      $\hat h_f$ & 0.0075 \\
      \bottomrule
   \end{tabular}
\end{center}
where the $\hat h_f = 0.0075$  is the value that corresponds to 10k ft.

Note, while the thrust to weight ratio is approximately 15 for rockets for IREC, most big rockets have $\hat F$ closer to 1.5! The next section shows this is actually very close to the optimum.

\section{Optimization Results}

A relatively brute force form of optimisation is attempted, in the interest of time. A Mathematica function is written to solve the dynamics equations, given the four parameters. The apogee height is returned by this function. The numerical schemes used are Mathematica's 'automatic' choices, which generally performs well, even through stiff systems. Since the problem is initial valued, it is fairly trivial to solve numerically.

A few simulated trajectories are shown below, as samples. It is hard to believe that these are optimally sized vehicles.

%\FloatBarrier
\begin{figure}[htbp]
   \centering
   \includegraphics[width=0.8\linewidth]{sample_flights.eps}
   \caption{Sample simulated flights based on data from 2018 reports. Red indicates thrusting, blue indicates coasting.}

      \begin{tabular}{@{} llcccc|ccc@{}}
         \toprule
         Team &Type & $C_D$ (est) & $c$ (m/s, assumed) & dia (in) & $m_0$ (kg) &  $x$ & $m_p/m_0$ & $T/W$ \\
         \midrule
         McGill & Solid & 0.5 & 2000 & 5 & 24 & 64.6 &0.146 & 8.8\\
         Waterloo& Hybrid & 0.5 & 2000 & 6 & 64.8 & 34.48 &0.280 & 1.5\\
         UCLA & Hybrid &0.5 & 2000 & 6 & 26.7 & 83.7 & 0.21 & 8.5\\
         \bottomrule
      \end{tabular}
    \label{fig:}
\end{figure}
%FloatBarrier

Now we can see the trade between thrust to weight ratio and propellant mass fraction.

\begin{landscape}
%\FloatBarrier
\begin{figure}[htbp]
   \centering
   \includegraphics[width=\linewidth]{Tw-MR_contours.eps}
   \caption{}
   \label{fig:}
\end{figure}
%FloatBarrier
\end{landscape}

The red line indicates the 10k target altitude (assuming $c = 2000~m/s$). This shows that for a range of $x$, the easiest to design scenarios are for T/W>3, and propellant mass fraction around 15\%. Below a thrust to weight ratio of 2, the height is very sensitive to the propellant mass fraction.

It is also interesting to see that as the propellant mass fraction increases, it becomes better to reduce thrust to weight ratio towards T/W $\sim$ 2.

Ultimately however, we need to find a design that can achieve the desired altitude, while minimising the total mass and thrust level required. If we limit max thrust to 1~kN, and assume $c=2000$~m/s and $c_d = 0.5$, we can figure out possible designs:

%\FloatBarrier
\begin{figure}[htbp]
   \centering
   \includegraphics[width=0.8\linewidth]{results.eps}
   \caption{}
   \label{fig:}
\end{figure}
%FloatBarrier

This figure shows the required propellant mass fraction is about 17\%, over a range of vehicle masses. It is obvious that reducing the vehicles mass would be beneficial, as it gives more flexibility in the future, and increases the acceleration, and therefore stability, but is also important for the propellant mass fraction to be as close to 17\% as possible.

Why is there such a steep slope to the graphs? One way to think about it is as follows. For very large thrust to weight, the rocket burns very rapidly, and acts as impulse. From there, the vehicle is basically passive, and the ratio of drag to inertia (the parameter $x$) controls the final altitude. Therefore in the limit that thrust to weight becomes large,

\end{document}


\documentclass[10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}

% partial derivative as a fraction
\newcommand{\fracpd}[2]{
  \ensuremath{\frac{\partial #1}{\partial #2}}
}

\begin{document}

% --------------------------------------- %
% Section
% --------------------------------------- %
\section{Introduction}

  This repository holds the solutions to a general set of growth models that incorporate the following explore the differences between

  \begin{itemize}
    \item One Agent vs Two Agent
    \item One Good vs Two Goods
    \item Time Additive Preferences vs Recursive Preferences
    \item Constant Volatility vs Stochastic Volatility
  \end{itemize}

  By solve the 16 possible versions of this model, we are able to isolate the effects of each bell and whistle that we include in the model.

% --------------------------------------- %
% Section
% --------------------------------------- %
\section{One Agent One Good General Model}

  We will write our one agent general unscaled model as the following:

  \begin{align*}
    J_t(k_t, x_t, v_t) &= \max_{k_{t+1}} \left[(1 - \beta) c_t^{\rho} + \beta \mu(J_{t+1}(k_{t+1}, x_{t+1}, v_{t+1}))^{\rho} \right]^{\frac1\rho} \\
    \text{Subject To }& \\
    c_t &= \left[ \eta k_{t}^{\nu} + (1 - \eta) z_t^{\nu} \right]^{\frac1\nu} + (1 - \delta) k_t - k_{t+1} \\
    x_{t+1} &= A x_{t} + B v_t^{\frac{1}{2}} \varepsilon_{1, t+1} \\
    v_{t+1} &= (1 - \phi_v) \bar{v} + \phi_v v_{t} + \tau \varepsilon_{2, t+1} \\
    \log(z_t) &= \log(z_{t-1}) + \log(\bar{g}) + x_t
  \end{align*}

  We could then scale the model by dividing by $z_t$ to give us (will not both writing tildes for now -- everything here is divided by $z_t$)

  \begin{align*}
    J_t(k_t, x_t, v_t) &= \max_{\chi_{t}} \left[(1 - \beta) c_t^{\rho} + \beta \mu(J_{t+1}(k_{t+1}, x_{t+1}, v_{t+1}) g_{t+1})^{\rho} \right]^{\frac1\rho} \\
    \text{Subject To }& \\
    c_t &= \left[ \eta k_{t}^{\nu} + (1 - \eta) \right]^{\frac1\nu} + (1 - \delta) k_t - \chi_t \\
    \chi_t &= k_{t+1} g_{t+1} \\
    x_{t+1} &= A x_{t} + B v_{t}^{\frac{1}{2}} \varepsilon_{1, t+1} \\
    v_{t+1} &= (1 - \phi_v) \bar{v} + \phi_v v_{t} + \tau \varepsilon_{2, t+1} \\
    \log(g_t) &= \log(z_t) - \log(z_{t-1}) = \log(\bar{g}) + x_t
  \end{align*}

  Notice we can get constant volatility by allowing $\tau = \phi_v = 0$ or time separable preferences by $\rho = \alpha$.

% --------------------------------------- %
% Section
% --------------------------------------- %
\section{One Agent Two Goods General Model}

% --------------------------------------- %
% Section
% --------------------------------------- %
\section{Two Agent One Good General Model}

% --------------------------------------- %
% Section
% --------------------------------------- %
\section{Two Agent Two Goods General Model}

\end{document}


%\subsection{Symbolic Numeric Computation}

\bigskip
\noindent
\textbf{2.3. Sparse Computation}
\bigskip

%There are important applications in engineering, particularly control theory and linear systems theory, where physical models are represented as polynomials and polynomial matrices (or more generally rational functions and rational matrices). Properties of such models are then represented in terms of arithmetic in polynomial or polynomial matrix domains. However, while the polynomial algebra for such representations assume exact arithmetic, the input data is typically measured (i.e. inexact) values. For these {\em symbolic-numeric} problems \cite{corless2} the arithmetic theory needs to be properly defined, and algorithms need to be both efficient in terms of operation count and, more importantly, numerically correct. The main direction in this area is sparse interpolation and exponential approximation.
%arithmetic with approximate rational functions. The common thread in these two topics is their relation with Prony types of problems.

Sparse polynomial interpolation is the problem of recovering a representation of a multivariate polynomial over a basis (typically the standard power basis).  This is an inverse problem where we need to determine the parameters - exponents, coefficients, support - of the polynomial given some evaluation values.  This problem is closely connected to the shape from moments problem  in the plane \cite{MilanfarGolub} along with the sparse decomposition of a signal built as a linear mixture of complex exponentials \cite{HuaSarkar}. In these cases efficient algorithms need to depend on the number of terms in the sparse representation rather than the possible number of terms found in a dense representation. Sparse representations
are common in applications. For example, the recovery of low rank information from sparse sampling is at the core of the
compressed sensing paradigm \cite{candes}.  Sparse representations pose serious issues when these inverse problem computations are done in floating point, approximate arithmetic environments.

\newpage
\bigskip
\noindent
{\bf Previous Work}
\bigskip

The most significant challenge for sparse interpolation is that this is a nonlinear problem compared to the linear problem of dense interpolation. We have previously shown in [J16] that this problem is closely related to problems solved via Prony's method from 1795. This in turn allowed us to take advantage of modern numerical work by Golub et al \cite{golub1} to solve this problem via the use of generalized Hankel eigenvalues. The issue of the poor numerical conditioning of the generalized Hankel eigenvalue problem (indeed bounded below by an exponential factor) reported in  \cite{begola} was overcome by using randomization in determining sampling points. We refer the reader to
 \cite{potts} for other methods for solving sparse problems in numerical environments.
%This topic is also the theme of our Dagstuhl meeting in June 2015 and a BIRS workshop in 2016.
Sparse interpolation and exponential analysis are the themes of our Dagstuhl meeting in June 2015 and BIRS workshop in 2016.

\bigskip
\noindent
{\bf Proposed Research}
\bigskip

Sparse interpolation is typically considered for multivariate polynomials defined over the standard polynomial basis. However, there are a number of applications where sparse representations coming from Chebyshev and Pochhammer polynomials \cite{gll2,potts2} are more useful - the former being particularly interesting as it allows for sparse modeling of fourier cosine data. We propose to address the computational challenges in finding sparse representations in other orthogonal and/or interpolation bases (e.g. \cite{corless}) over approximate floating point environments. In the short term we plan to investigate the use of structured linear algebra formulations represented in terms of Krylov type matrices. However we expect that even analysing the numerical sensitivities of this problem will be extremely challenging.

We are interested in higher dimensional versions of exponential and polynomial interpolation. The standard shape-from-moments problem reconstructs 2-D polygonal shapes from 2-D moment data. Some previous work has been done on higher dimensional shapes \cite{cuyt} but the recent paper by Gravin et al \cite{lasserre}, formulating an $n$-D shape-from-moments problem using Brion's formula to find the $n$ dimensional vertices of a polygonal object from higher dimensional moments seems most promising. A longer term challenge is to actually compute the $n$ dimension coordinates in a provably numerically stable way and to understand the conditioning issues that arise from this problem \cite{cchlc}. We propose to look at this problem by making use of tools from structured linear algebra but with the structures coming from multivariate polynomial arithmetic both for power and alternate bases.
%Classical structured matrices such as Hankel and Toeplitz linearly describe univariate polynomial arithmetic identities.
%As before, our plan is to do this for both power polynomial or exponential bases along with a number of alternate polynomial bases.

\bigskip
\noindent
{\bf 3.   Anticipated Impact and Long Term Objectives}
\bigskip

The proposed research in symbolic matrix algorithms can potentially provide significant advancement in symbolic solutions and properties of differential equations. Our proposed work on scalings and finite group actions should have considerable impact on the solving of multivariate polynomial and dynamical systems of equations. Similarly our work on sparse interpolation in numerical environments would have considerable impact for
addressing numeric issues arising in sparse problems. Our overall objective is to create tools for symbolic computation that allow computer algebra systems to be applied in practical and important problems in science and engineering. In all cases the algorithms created in this research will be implemented, usually in the Maple system, and hence have wide availability. This is consistent with what has happened in the past with the impact of such core Maple packages as Plots, PlotTools, DEtools, MatrixPolynomialAlgebra and such important functionality as symbolic indefinite integration and solving of linear differential equations.

%Our second research direction in this area is the symbolic-numeric computation of rational functions.
%Symbolic-numeric computation with polynomials, including such operations as finding zeros and greatest common divisors has been a well studied topic over the last two decades in computer algebra. However the same cannot be said for working with rational functions. This is a bit surprising since for applications (for example function approximations or input-output problems from control theory), one typically encounters rational rather than polynomial functions. For rational functions understanding ```close'' properties involves understanding the zeros and poles of nearby rational functions. For example in the case of rational approximation, the nearby zeros and poles have significant impact on convergence and other properties.  This becomes a difficult issue when working over a numerical environment. Interestingly enough one cannot just work with symbolic-numeric arithmetic with numerators and denominators separately. Here the main issue is one of missing or spurious poles, that is, poles with a nearby zero or poles with small residuals.  Recent attempts to address the notion of closeness includes the %introduction of the
%concept of
%robust rational approximants found in \cite{gonnet} and the notion of well-conditioned rational approximants from the interesting new paper \cite{matos}.

%We propose two separate directions for research in this area, both with high impact and long term in nature. The measures for closeness given in \cite{matos} make use of unstructured
%condition numbers. We propose to replace these measures by structured condition numbers as was done earlier in case of numerically coprime polynomials \cite{coprime}. We would expect the result that the ``nearby regions''  be enlarged and the computation of the structured measures more efficient. A second problem is to change our representation for rational functions from zero-pole to partial fraction decomposition and then look for measures of closeness. We note that this would require only the poles of a rational function, which can be viewed as a Prony type of problem, and which is better understood in a numerical environment.

%{\bf Arithmetic with Differential Operators : }
%Symbolic/numeric computation with differential operators considers the algebraic operations on operators having polynomial coefficients whose coefficients in turn are approximate numbers. Preliminary work defining basic operations suchas one sided GCDs have recently been presented
%\cite{haraldson}.


\section{Preliminaries}
\label{sect:dssat-preliminaries}

\subsection{Dependency quantified Boolean formula}
\label{sect:dssat-dqbf}
DQBF is formulated as \textit{multiple-person alternation} by Peterson and Reif~\cite{Peterson1979}.
In contrast to the \textit{linearly ordered} quantification used in QBF,
i.e., an existentially quantified variable depends on all of its preceding universally quantified variables,
the quantification structure in DQBF is extended with \textit{Henkin quantifiers},
where the dependency of an existentially quantified variable is explicitly specified.

A DQBF $\Qf$ over a set $V=\{x_1,\ldots,x_n,y_1,\ldots,y_m\}$ of variables is of the form:
\begin{align*}
    \Qf=\forall x_1,\ldots,\forall x_n,\exists y_1(\dep{y_1}),\ldots,\exists y_m(\dep{y_m}).\pf(x_1,\ldots,x_n,y_1,\ldots,y_m),
\end{align*}
where each $\dep{y_j}\subseteq\{x_1,\ldots,x_n\}$ denotes the set of universally quantified variables that $y_j$ depends on,
and Boolean formula $\pf$ over $V$ is quantifier-free.
We denote the set $\{x_1,\ldots,x_n\}$ (resp. $\{y_1,\ldots,y_m\}$) of universally (resp. existentially) quantified variables of $\Qf$ by $\uvs$ (resp. $\evs$).

A DQBF $\Qf$ is satisfiable if for each variable $y_j$,
there exists a Boolean function $f_j:\av{\dep{y_j}}\mapsto\booldom$,
such that matrix $\pf$ becomes a tautology over $\uvs$
after substituting variables in $\evs$ with their respective Boolean functions.
The set $\skf=\{f_1,\ldots,f_m\}$ of Boolean functions is called a set of \textit{Skolem} functions for $\Qf$.
In other words, $\Qf$ is satisfied by $\skf$ if the following QBF valuates to $\top$:
\begin{align}
    \label{eq:dssat-dqbf-satisfiable}
    \forall x_1,\ldots,\forall x_n.\pf(x_1,\ldots,x_n,f_1,\ldots,f_m),
\end{align}
where $\pf(x_1,\ldots,x_n,f_1,\ldots,f_m)$ represents the formula obtained by substituting existentially quantified variables in $\pf$ with their respective Skolem functions.
We extend the notation for cofactors and denote $\pf(x_1,\ldots,x_n,f_1,\ldots,f_m)$ by $\pcf{\pf}{\skf}$.
The satisfiability problem of DQBF is NEXPTIME-complete \cite{Peterson2001}.

\subsection{Decentralized POMDP}
\label{sect:dssat-dec-pomdp}
Dec-POMDP is a formalism for multi-agent systems under uncertainty and with partial information.
Its computational complexity is NEXPTIME-complete~\cite{Bernstein2002}.
In the following, we briefly review the definition, optimality criteria,
and value function of Dec-POMDP from the literature~\cite{Oliehoek2016}.

A Dec-POMDP is specified by a tuple $\mathcal{M}=(I,S,\{A_i\},T,\rho,\{O_i\},\Omega,\Delta_0,h)$, where
$I=\{1,\ldots,n\}$ is a finite set of $n$ agents,
$S$ is a finite set of states,
$A_i$ is a finite set of actions of Agent $i$,
$T:S\times(A_1\times\cdots\times A_n)\times S\mapsto [0,1]$ is a transition distribution function with
$T(s,\Vec{a},s')=\Pr[s'|s,\vec{a}]$,
the probability to transit to state $s'$ from state $s$ after taking actions $\vec{a}$,
$\rho:S\times(A_1\times\cdots\times A_n)\mapsto\mathbb{R}$ is a reward function with
$\rho(s,\vec{a})$ giving the reward for being in state $s$ and taking actions $\vec{a}$,
$O_i$ is a finite set of observations for Agent $i$,
$\Omega:S\times(A_1\times\cdots\times A_n)\times(O_1\times\cdots\times O_n)\mapsto[0,1]$ is an observation distribution function with
$\Omega(s',\Vec{a},\vec{o})=\Pr[\vec{o}|s',\vec{a}]$,
the probability to receive observation $\vec{o}$ after taking actions $\vec{a}$ and transiting to state $s'$, $\Delta_0:S\mapsto [0,1]$ is an initial state distribution function with $\Delta_0(s)=\Pr[s^0 \equiv s]$,
the probability for the initial state $s^0$ being state $s$,
and $h$ is a planning horizon, which we assume finite in this work.

\begin{figure}[t]
    \centering
    \includegraphics[scale=1.5]{fig/build/dec-pomdp-example.pdf}
    \caption{A two-agent Dec-POMDP example}
    \label{fig:dssat-dec-pomdp-state-graph}
\end{figure}

\begin{example}
    An example Dec-POMDP $\mathcal{M}$ with two agents and two states $s_p,s_q$
    is shown in~\cref{fig:dssat-dec-pomdp-state-graph}.
    The goal of the agents is to make a correct agreement on the current state.
    They have an action set $A_1=A_2=\{a_p,a_q\}$,
    where $a_p$ (resp. $a_q$) is used to guess that the current state is $s_p$ (resp. $s_q$).

    Under the assumption of partial observation, the agents cannot access the current state of $\mathcal{M}$.
    Instead, they have two different observations $o_p$ and $o_q$.
    We assume that an agent will receive $o_p$ (resp. $o_q$) after the current state transits to $s_p$ (resp. $s_q$) with probability $\Omega(s_p,o_p)$ (resp. $\Omega(s_q,o_q)$).

    If both agents guess correctly, they will receive a reward of $1$,
    and $\mathcal{M}$ will transit to a next state with equal probability.
    In the state-transition graph, observe that in state $s_p$ (resp. $s_q$),
    there are two outgoing edges labeled with a tuple $(a_p,a_p,1)$ (resp. $(a_q,a_q,1)$),
    which describes the agents' actions and the reward.
    These two edges will be taken with probability $0.5$ if the preconditions are met.

    On the other hand, if one of the agents makes a wrong guess,
    they will receive a reward of $-1$, and $\mathcal{M}$ will stay in the current state.
    In the state-transition graph, observe that in state $s_p$ (resp. $s_q$),
    there is a self-loop labeled with tuples $(a_q,A_2,-1)$ and $(A_1,a_q,-1)$
    (resp. $(a_p,A_2,-1)$ and $(A_1,a_p,-1)$).
    These tuples indicate that if one of the agent makes a wrong guess,
    they will receive a reward of $-1$ regardless of the guess of the other agent.

    Note that the agents cannot communicate with each other.
    Their actions must be solely based on their own observations.
\end{example}

Given a Dec-POMDP $\mathcal{M}$,
we aim at maximizing the expected cumulative reward $\mathbb{E}[\sum_{t=0}^{h-1}\rho(s^t,\vec{a}^t)]$ through searching an optimal \textit{joint policy} for a team of agents.
Specifically, a \textit{policy} $\pi_i$ of Agent $i$ is a mapping from the agent's \textit{observation history},
i.e., a sequence of observations $\underline{o_i^t}=o_i^0,\ldots,o_i^t$ received by Agent $i$,
to an action $a_i^{t+1}\in A_i$.
A joint policy for the team of agents $\vec{\pi}=(\pi_1,\ldots,\pi_n)$ maps the agents' joint observation history $\vec{\underline{o}}^t=(\underline{o_1^t},\ldots,\underline{o_n^t})$ to actions $\vec{a}^{t+1}=(\pi_1(\underline{o_1^t}),\ldots,\pi_n(\underline{o_n^t}))$.
We shall focus on deterministic policies only,
as it is shown that every Dec-POMDP with a finite planning horizon has a deterministic optimal joint policy~\cite{Oliehoek2008}.

The quality of a joint policy $\vec{\pi}$ is measured by its expected cumulative reward.
The \textit{value} of a joint policy is hence defined to be $\mathbb{E}[\sum_{t=0}^{h-1}\rho(s^t,\vec{a}^t)|\Delta_0,\vec{\pi}]$.
The \textit{value function} $V^\pi$ can be computed in a recursive manner, where for $t=h-1$,
\begin{align*}
    V^\pi(s^{h-1},\vec{\underline{o}}^{h-2})=\rho(s^{h-1},\vec{\pi}(\vec{\underline{o}}^{h-2})),
\end{align*}
and for $t<h-1$,
\begin{align}\label{eq:dssat-bellman}
    V^\pi(s^t,\vec{\underline{o}}^{t-1})=\rho(s^t,\vec{\pi}(\vec{\underline{o}}^{t-1}))+
    \sum_{s^{t+1}\in S}\sum_{\vec{o}^t\in\vec{O}}\Pr[s^{t+1},\vec{o}^t|s^t,\vec{\pi}(\vec{\underline{o}}^{t-1})]V^\pi(s^{t+1},\vec{\underline{o}}^{t}).
\end{align}
The probability $\Pr[s^{t+1},\vec{o}^{t}|s^t,\vec{\pi}(\vec{\underline{o}}^{t-1})]$ is the product of
the transition probability $T(s^t,\vec{\pi}(\vec{\underline{o}}^{t-1}),s^{t+1})$ and
the observation probability $\Omega(s^{t+1},\vec{\pi}(\vec{\underline{o}}^{t-1}),\vec{o}^{t})$.
\Cref{eq:dssat-bellman} is also called the \textit{Bellman equation} of Dec-POMDP.
Denoting the empty observation history at the first stage (i.e., $t=0$) with the symbol $\vec{\underline{o}}^{-1}$, the value $V(\vec{\pi})$ of a joint policy equals $\sum_{s^0\in S}\Delta_0(s^0)V^\pi(s^0,\vec{\underline{o}}^{-1})$.


\chapter{Discretization Procedures}

Discretization procedures for elastic formulation have been developed since the early $60$'s under diverse setting oriented mainly in civil-engineering fields. In this section, it will be presented following literature  \cite{ern2004theory}, \cite{raviart1983introduction} a finite-element discretization scheme for the space-domain and a standard $\beta$-Newmark time-domain discretization, thus a complete numerical formulation for various elastic models implemented in \texttt{FEniCS}, a state-of-art library for such purposes joint with \texttt{Python} language.

\section{Numerical Schemes}
To discretize the elastodynamic model, it will be assumed that the solution is defined on a Banach space $\mathbf{V}$, in which the elasticity operator defined from the tensor $\mathbf{C}^{hom} = (C^{hom}_{ijkl})_{ijkl}$ by:
\begin{equation*}
    \mathcal{I}_{C^{hom}} (u,v) := \int \limits_{\Omega} C^{hom}_{ijkl}\mathbf{e}_{kl}(u) \mathbf{e}_{ij}(v) \, dx \quad \forall u,v \in \mathbf{V}
\end{equation*}
is well-defined in the sense that conditions of coercivity on the operator are assured from the uniformly ellipticity of $C^{hom}_{ijkl}$.

\subsection{Approximation by Finite Spaces}
The solution of the elastodynamic problem will be found as projection solutions of finite dimensional subspaces that approximate to solution space\footnote{Such workflow is defines the approximation theory of PDE solutions and the so-called finite elements method \cite{ern2004theory}.}, in this case $\mathbf{H}^1(\Omega, \Gamma_D)$.
Let $\{\mathbf{V}_h \}_{0 \leq h \leq 1}$ be a family of finite-dimensional subspaces of $\mathbf{V}$, assume that there exist a dense subspace $\mathbf{W} \subset \mathbf{V}$, a linear interpolator $\Pi_h \in \mathcal{L}(\mathbf{W};\mathbf{V}_h)$, integer $k > 0$ such that our finite dimensional solution approximation $\Pi_{h} $ with associated to a mesh size $h>0$ satisfies:
\begin{equation*}
    \Vert v - \Pi_h v \Vert_{\mathcal{L}(\mathbf{W};\mathbf{V}_h)} \leq h^{k+1} \Vert v \Vert_{\mathbf{W}} \quad \forall v \in \mathbf{W}
\end{equation*}
%In particular, the above assumptions are assured in REFERENCE: HUDGENDS PAPER.
\begin{rem}
In our case under study it is used $\mathbf{V} = \mathbf{L}^2(\Omega)$ and $\mathbf{W} = \mathbf{H}^1(\Omega, \Gamma_D)$ being $\mathbf{V}_h$ the $\mathbf{H}^1$-conformal finite element spaces using as reference element $\{ \hat{K}, \hat{P}, \hat{\sigma} \}$ of \textit{Lagrange} type with typical order $k \in \{1,2\}$, such that $\mathbb{P}_k \subset \hat{P}$ with $\mathbf{W} := \mathbf{H}^{k+1}(\Omega) \cap \mathbf{H}^1(\Omega, \Gamma_D)$
\end{rem}

Over such finite dimensional subspaces $\{ \mathbf{V}_h\}_{h>0}$ the approximate solution can be found, satisfying the problem for each $h>0$:
\begin{equation}
\label{ODE-Discretized}
    \left \{
    \begin{array}{cc}
        \text{Find } u_h \in \mathcal{C}^2(0,T; \mathbf{V}_h) & \text{ such that } \\
        (\rho^0 d_{tt} u_h(t), v_h)_{\Omega} + \mathcal{I}_{C^{hom}}(u_h(t), v_h) = (\mathbf{F}(t), v_h)_{\Gamma_N} & \forall v_h \in \mathbf{V}_h\\
        d_t u_h(0) = u_h(0) = \mathbf{0} &
    \end{array}
    \right.
\end{equation}

Problem (\ref{ODE-Discretized}) corresponds to a finite linear PDE system in time for the variable $u_h(t)$ where the existence can be obtained by application of the spectral theory decomposing the elastic operator in its spectrum. The treatment is similar to the procedure proposed in the above section \cite{raviart1983introduction}.

The space discretization then is obtained from (\ref{ODE-Discretized}) which corresponds to a system of Ordinary Differential Equations (ODEs). Indeed, let $\{ \varphi_1, \dots, \varphi_{N(h)} \}$ denote a basis for the finite dimensional space $\mathbf{V}_h$ or so-called global shape functions for $\mathbf{V}_h$, then for all $t \in (0,T)$ the approximate solution $u_h(t) \in \mathbf{V}_h$ can be expanded as
\begin{equation*}
    u_h(\mathbf{x},t) = \sum \limits_{i=1}^{N(h)} \mathbf{U}_i(t) \varphi_i
\end{equation*}
where it is used the notation $\mathbf{U}(t) = (U_i(t))_{1 \leq i \leq N} \in \mathbb{R}^{N(h)}$.

Now, introducing also $\mathbf{F}_h(t) = \big( (\mathbf{F}(t), \varphi_i)_{\Omega} \big)_{1 \leq i \leq N}\in \mathbb{R}^{N(h)}$ with the so-called stiffness $\mathcal{A}(t) \in \mathbb{R}^{N(h) \times N(h)}$ and stress $\mathcal{M} \in \mathbb{R}^{N(h) \times N(h)}$ matrices respectively by:
\begin{equation*}
    \mathcal{A}_{ij}(t) = \mathcal{I}_C(\varphi_j, \varphi_i), \, \mathcal{M}_{ij} = (\sqrt{\rho^0} \varphi_i , \sqrt{\rho^0}\varphi_j)_{\Omega} \quad 1 \leq i,j \leq N(h)
\end{equation*}

By the previous hypothesis $\mathcal{A}(t)$ is symmetric and positive-definite whereas $\mathcal{M}_{ij}$ is positive definite. Under such notation, it follows the time-dependent matrix form formulation :
\begin{equation}
    \label{MatrixFormulation}
    \left \{
    \begin{array}{cc}
        \text{Find } \mathbf{U} \in \mathcal{C}^2(0,T; \mathbb{R}^{N(h)\times N(h)}) & \text{ such that} \\
        \mathcal{M} d_{tt} \mathbf{U}(t) + \mathcal{A}\mathbf{U}(t) = \mathbf{F}_h (t) & \text{ in }(0,T)\\
        d_{t} \mathbf{U}(0) = \mathbf{U}(0)  = \mathbf{0}&
    \end{array}
    \right.
\end{equation}
which describes the full space discretization scheme by means of the FEM method, and enabling the use of time discretization techniques for the resulting ODE problem (\ref{MatrixFormulation}). In particular as will be seen in the next section the so-called $\beta$-Newmark scheme. \footnote{The implementation of such space discretization is done in Python using a state-of-art open-source project called \texttt{FEniCS} \cite{logg2012automated}, defined as a set of specific core component such as \texttt{DOLFIN}, \texttt{UFL},  \texttt{UFC}, etc. It enables the automatic solution of differential forms implementing the Theory of Finite Elements with numerically optimized libraries for arithmetic computations. The project is an international collaboration initiated in 2003 between the University of Chicago and Chalmers University of Technology currently under development from a variety of institutions.}

\subsection{Time Discretization}
Let us note that (\ref{MatrixFormulation}) defines a standard \textit{Cauchy} ODE problem. To solve numerically such system, it will be introduced an uniform time-step discretization of $(0,T)$ in the form $\Delta t = T/N_T$ such that:
\begin{equation*}
    t_n = n \Delta t, \quad 0 \leq n \leq N_T
\end{equation*}
being $N_T \in \mathbb{N}^*$ some fixed number of time steps.

It will be found for each $n \in \{1,\dots, N_T \}$ an approximate sequence tuple $(u_n, v_n, a_n)$ of the solutions $(u(t_n), \partial_{t} u(t_n), \partial_{tt} u(t_n))$ being the method chosen the so-called $\beta$-\textit{Newmark}, a well-known scheme to study mechanically driven behavior \cite{raviart1983introduction}.

Taking into account the time-domain regularity from the solution $u^{(0)}(t, \mathbf{x}) := u(t,\mathbf{x})$ of the homogenized PDE problem (result analogous to \ref{BootstrapingProp}), let us note that by using the \textit{Taylor} expansion on $u \in \mathcal{C}^{p}(0,T;\mathbf{H}^1(\Omega, \Gamma_D))$ and the mean value theorem that for the displacement at time $t_{n+1}$ it follows:
\begin{equation*}
    u(t_{n+1}) = u(t_n) + \Delta t \, \partial_{t} u(t_n) + \Delta t^2 \, \big( \beta \partial_{tt} u(t_{n+1}) + (\frac{1}{2} - \beta) \partial_{tt} u(t_{n+1}) \big) + \mathcal{O}(\Delta t^3)
\end{equation*}
and for the velocity
\begin{equation*}
    \partial_{t} u(t_{n+1}) = \partial_{t} u (t_{n}) + \Delta t \, \big( \gamma \partial_{tt} u(t_{n+1}) + (1-\gamma) \partial_{tt} u(t_n) \big) + \mathcal{O}(\Delta t^2)
\end{equation*}
being $\beta, \gamma$ two parameters with $0 < 2\beta<1,\, 0 < \gamma < 1$.
The $\beta$-Newmark scheme consist then in a approximation of the above equations by using a finite difference scheme in the form:
\begin{align}
    \label{TimeDif-Scheme}
    u_{n+1} &= u_{n} + \Delta t\, v_{n} + \Delta t^2 \, \big( \beta a_{n+1} + (\frac{1}{2} - \beta) a_n \big) \\
    v_{n+1} &= v_n + \Delta t\, \big( \gamma a_{n+1} + (1-\gamma) a_{n} \big)
\end{align}
From (\ref{TimeDif-Scheme}) it is defined the numerical procedure by a two-step update given as follows:
\begin{align}
    \label{TwoStage-Update}
    \text{(Stage 1)}\longrightarrow  a_{n+1} &= \frac{1}{\beta \Delta t^2} ( u_{n+1}-u_n - \Delta t \, v_n) - \frac{(1-2\beta)}{2 \beta} a_n, \quad \forall \, 0 \leq n \leq N_T-1 \\
    \text{(Stage 2)}\longrightarrow v_{n+1} &= v_n + \Delta t \, \big( (1-\gamma) a_n + \gamma a_{n+1} \big), \quad \forall \, 0 \leq n \leq N_T-1
\end{align}

Let us now show the precision of the $\beta$-\textit{Newmark} scheme. Note that the elastodynamic equation contains two derivatives in time, so that taking into account the above and applying again \textit{Taylor} expansion and the mean value theorem, it follows as $\Delta t$ tends to zero that:

\begin{multline}
    u(t_{n+1}) = u(t_{n}) + \Delta t \, \partial_{t} u(t_n) + \\
    \Delta t \, \big( \beta \partial_{tt} u(t_{n+1}) + (\frac{1}{2}- \beta) \partial_{tt} u(t_n) \big) + \Delta t^3 (\frac{1}{6}-\beta) \partial_{ttt}u(t_n) + \mathcal{O}(\Delta t^4)
\end{multline}

\begin{multline}
    \partial_{t} u(t_{n+1}) = \partial_{t} u(t_n) + \Delta t\, \big( \gamma \partial_{tt} u(t_{n+1}) + \\
    (1-\gamma) \partial_{tt}u(t_n) \big) + \Delta t^2 \, (\frac{1}{2}-\gamma) \partial_{ttt} u(t_n) + \mathcal{O}(\Delta t^3)
\end{multline}

so that, the scheme results of precision $\mathcal{O}(\Delta t)$ for $\gamma \neq 1/2$ and $\mathcal{O}(\Delta t^2)$ for $\gamma = 1/2$.

Applying now such two-step scheme (\ref{TwoStage-Update}) over (\ref{MatrixFormulation}) it follows the matrix system update procedure:
\begin{align}
    \label{MatrixSystemUpdate}
    \frac{1}{\beta \Delta t} \mathcal{M}(\mathbf{U}_{n+1} - \mathbf{U}_{n} - \Delta t\, \mathbf{V}_n) - \frac{1}{\beta}(\frac{1}{2}- \beta) \mathcal{M}\mathbf{A}_n + \mathcal{A}\mathbf{U}_{n+1} &= \mathbf{F}_h \quad 0 \leq n \leq N_T-1 \\
    \frac{1}{\gamma \Delta t} \mathcal{M}(\mathbf{V}_{n+1} - \mathbf{V}_{n}) - \frac{1}{\gamma}(1-\gamma) \mathcal{M}\mathbf{A}_n + \mathcal{A}\mathbf{U}_{n+1} & = \mathbf{F}_h \quad 0 \leq n \leq N_T-1
\end{align}

Note that such a time step iteration (\ref{MatrixSystemUpdate}) corresponds to solve the linear system of equations defined for the function $\mathbf{U}_{n+1}$ in the form:
\begin{equation*}
    (\mathcal{M}+ \beta \Delta t^2 \, \mathcal{A}) \mathbf{U}_{n+1} = \mathbf{F}_{n+1}
\end{equation*}
being $\mathbf{F}_{n+1} \in \mathbb{R}^{I(h)}$ known and then update the solution $\mathbf{U}_n$ field using the (\ref{TwoStage-Update}).
Now, since the $\beta \geq 0$, if follows that the $\mathbf{R}^{I(h)} \times \mathbf{R}^{I(h)}$ matrix $(\mathcal{M}+ \beta \Delta t^2 \mathcal{A})$ is positive definite and moreover its symmetric.

\section{Dynamic Type Models}
The discretization procedures defined before enables the implementation of step-wise procedures of homogenized fully elastodynamic models, its attenuated version to bypass resonance effects shown in the frequency domain formulation and Viscoelastic formulations.
\subsection{Fully Elastodynamic}

Taking into account our homogenized elastodynamic model (\ref{HomogenizedPDE}) described explicitly:
\begin{equation}
    \label{HomPDE-Model}
    \left \{
    \begin{array}{cc}
        \text{Find $u \in \mathcal{C}^2(0,T;\mathbf{H}^1(\Omega, \Gamma_D))$} & \text{such that} \\
        \rho^{0} \partial_{tt} u^{(0)}(t,\mathbf{x}) - \nabla \cdot \sigma^{0} (u^{(0)}(t,\mathbf{x}) ) = \mathbf{0} & \text{ in } (0,T)\times \Omega \\
        \sigma^{0}_{ij}(u^{(0)}(t, \mathbf{x})) = C^{hom}_{ijkl}\mathbf{e}_{kl,x}(u^{(0)}(t,\mathbf{x})) & \text{ in } (0,T)\times \Omega \\
        u^{(0)}(t, \mathbf{x}) = \mathbf{0} & \text{ on } (0,T)\times \Gamma_D \\
        \sigma^{0}(u^{(0)}(t, \mathbf{x})) \cdot n = \mathbf{F}(t, \mathbf{x}) & \text{ on } (0,T)\times \Gamma_N
    \end{array}
    \right .
\end{equation}
the discretization procedure over time applied on (\ref{HomPDE-Model}) turn into the update scheme for each $n \in \{1,\dots, N\}$ in the form:
\begin{equation*}
    \label{HomPDE-TimeUpdate}
    \frac{\rho^{0}}{\beta (\Delta t)^2} u_{n+1} - \nabla \cdot \sigma(u_{n+1}) = \frac{\rho^{0}}{\beta (\Delta t)^2} ( u_{n} + (\Delta t) v_n ) + \rho^{0}\frac{(1-2\beta)}{2\beta} a_n
\end{equation*}
with fields update (\ref{TwoStage-Update}).

\subsection{Elastodynamic Attenuated}
The presence of eigen-frequencies in the elastodynamic operator gives a bad numerical solution after solving the discrete system in the frequency domain. This problem can be bypassed using a regularization factor, or moreover, a kind of viscosity term which changes the eigen-frequencies and stabilizes the discrete system resulting in \textit{good} approximation to the experimental results.\\
In this case, we add a term which in viscoelastic literature resembles a \textit{Kelvin-Voigt} type behavior. It is added such term scaled with parameter $\epsilon$, so that the overall behavior is not abruptly disrupted but is well-posed in the set of real frequencies.

\begin{rem}
One possible way to see this technique is to consider the fact that we are moving the real frequencies $\omega$ to $\omega - i\epsilon$, it let us be away from the eigen-frequencies of the operator $\mathcal{I}_{C^{hom}}$, but the overall behavior of the real part remains close to the experimental setting.
\end{rem}

So, it is modeled the material as function of displacement $u(\mathbf{x},t) \in H^{1}(\Omega)$ (after the homogenization procedure) being $\Omega \subset \mathbb{R}^2$ a sufficiently regular domain, with \textit{Lipschitz} boundary $\partial \Omega := \Gamma_D \cup \Gamma_N$.
Explicitly, the regularized elastic model in defined by:
\begin{equation*}
    \left \{
    \begin{array}{cc}
        \rho^{0} \partial_{tt} u^{(0)} - \epsilon \partial_{t} u^{(0)} - \nabla \cdot \sigma^{0}(u^{(0)}) = \mathbf{0} & \text{in } (0,T)\times \Omega\\
        \sigma^{0}(u^{(0)}) =  \mathbf{C}^{hom}:\mathbf{e}(u^{(0)})  & \text{in }(0,T)\times \Omega\\
        \sigma^{0}(u^{(0)})\cdot n = \mathbf{F} & \text{on } (0,T)\times \Gamma_N\\
        u^{(0)} = \mathbf{0} & \text{on }(0,T)\times \Gamma_D \\
        u^{(0)} = \partial_t u^{(0)} = \mathbf{0}& \text{ on } \{t=0\}\times\Omega
    \end{array}
    \right .
\end{equation*}
where $\epsilon$ denotes a small regularization parameter associated to a Kelvin-Voigt type viscosity.
As before, it is considered a time-discretization $\beta$-Newmark scheme following the two-step update procedure for each $n \in \{1,\dots, N\}$:
\begin{align*}
    \text{(Stage 1)} &\longrightarrow a_{n+1} = \frac{1}{\beta (\Delta t)^2} (u_{n+1}-u_{n}-(\Delta t)v_n) - \frac{1-2\beta}{2\beta}a_n\\
    \text{(Stage 2)}& \longrightarrow v_{n+1} = v_n + \Delta t((1-\gamma)a_n + \gamma a_{n+1})
\end{align*}
It is then possible to define a numerically explicit scheme for our model, with update procedure at time $n+1$ given in the form:
\begin{align*}
    \frac{(\rho^{0}- \epsilon (\Delta t) \gamma)}{\beta (\Delta t)^2} u_{n+1} - \nabla \cdot u_{n+1} &= \frac{\rho^{0}}{\beta (\Delta t)^2} (u_n + (\Delta t)v_n) + \rho^{0}\frac{ (1-2\beta)}{2\beta}a_n \\
    & \, - \frac{\epsilon \gamma}{\beta (\Delta t)}(u_n + (\Delta t)v_n) - \epsilon (\Delta t)\gamma\frac{1-2\beta}{2 \beta} a_n
\end{align*}

\subsection{Kelvin-Voigt Viscoelastic Type}
Following the developments of the above ideas, a $\epsilon$-\textit{Kelvin-Voigt} viscoelastic bone model captures the main characteristics observed in biological and biomechanical literature of bone. In this case, the model is considered of linear elastic-viscous behavior with an $\epsilon$-regularization of the viscous part.
Thus, after applying the homogenization procedure, the following homogenized model is obtained:
\begin{equation*}
    \left \{
    \begin{array}{cc}
        \rho^{0} \partial_{tt} u^{(0)} - \nabla \cdot \sigma^{0}(u^{(0)}) = \mathbf{0} & \text{ in } (0,T)\times\Omega\\
        \sigma^{0}(u^{(0)}) =  \mathbf{C}^{hom}:\mathbf{e}(u^{(0)}) + \epsilon \mathbf{D}^{0}:\mathbf{e}(\partial_{t}u^{(0)}) & \text{ in }(0,T)\times \Omega\\
        \sigma^{0}(u^{(0)})\cdot n = \mathbf{F} & \text{ on }(0,T)\times\Gamma_N\\
        u^{(0)} = \mathbf{0} & \text{ on }(0,T)\times\Gamma_D \\
        u^{(0)} = \partial_t u^{(0)} = \mathbf{0} &  \text{ on } \{t=0\}\times\Omega
    \end{array}
    \right .
\end{equation*}
The standard discretization scheme is defined by a $\beta$-\textit{Newmark} implicit finite differences scheme for the time domain and FEM for the space domain. In this case, the time discretization is obtained in the usual two steps:
\begin{align*}
    \text{(Stage 1)} &\longrightarrow a_{n+1} = \frac{1}{\beta (\Delta t)^2} (u_{n+1}-u_{n}-(\Delta t)v_n) - \frac{1-2\beta}{2\beta}a_n\\
    \text{(Stage 2)}& \longrightarrow v_{n+1} = v_n + \Delta t((1-\gamma)a_n + \gamma a_{n+1})
\end{align*}
So that, the update scheme obtained at times $t_n = n+1$ in the form:
\begin{align*}
    \frac{\rho^{0}}{\beta (\Delta t)^2} u_{n+1} - \nabla \cdot \sigma_C^{0}( u_{n+1})  & - \frac{\gamma \Delta t}{\beta (\Delta t)^2} \nabla \cdot \sigma_D^{0}(u_{n+1}) \\
    &= \frac{\rho^{0}}{\beta (\Delta t)^2} (u_n + (\Delta t)v_n) + \rho^{0}\frac{ (1-2\beta)}{2\beta} a_n \\
    & + \nabla \cdot \sigma_D^{0}(v_n) + (1-\gamma)(\Delta t) \nabla\cdot \sigma_D^{0}(a_n) \\
    & - \frac{(\Delta t)\gamma}{\beta (\Delta t)^2}\nabla \cdot \sigma_D^{0}(u_n + (\Delta t)v_n) \\
    & - (\Delta t)\gamma\frac{1-2\beta}{2 \beta} \nabla \cdot \sigma_D^{0}(a_n)
\end{align*}

where it is used the notation $\sigma_C^{0}(w) = \mathbf{C}:\mathbf{e}(w)$ and $\sigma_D^{0}(w) = \mathbf{D}:\mathbf{e}(w)$ for $w \in \mathbf{H}^1(\Omega)$.

%\section{Frequency Domain Formulation}
%Finally, the study on frequency domain relates to various aspects, ranging from the study of the elastic operator and its eigen-frequencies, the proximity of the fourier implementation within the device recording procedure to the computational restrictions limiting the time-domain implementation.

%To this end, let us take Fourier transform to the time-dependent problem in such a way that it is considered particular solutions at frequency $\omega \in \mathbb{R}$ in the form:
%\begin{equation}
%    \label{FreqAnsatz}
%    u^{\epsilon}(\mathbf{x},t) = \hat{u}^{\epsilon}(\mathbf{x},\omega) e^{i \omega t}
%\end{equation}
%Again, following the homogenization procedure, the effective macroscopic PDE problem (\ref{HomPDE-Model}) is obtained:
%\begin{equation}
%    \label{VectorPDE-Freq}
%    \left \{
%    \begin{array}{cc}
%        -\rho^{hom} \omega^2 \hat{u}^{(0)}(\mathbf{x}) - \nabla \cdot \sigma^{hom} (\hat{u}^{(0)}(\mathbf{x}))=\mathbf{0}  & \text{ in }  \Omega \\
%        \sigma^{hom} (\hat{u}^{(0)}(\mathbf{x})) = \mathbf{C}^{hom}(\mathbf{x}): \mathbf{e} (\hat{u}^{(0)}(\mathbf{x})) & \text{ in } \Omega  \\
%        \hat{u}^{(0)}(\mathbf{x}) = \mathbf{0} & \text{ on } \Gamma_D\\
%        \sigma^{hom} (\hat{u}^{(0)}(\mathbf{x}))\cdot n = \hat{\mathbf{F}}(\mathbf{x}) & \text{ on } \Gamma_N \\
%    \end{array}
%    \right .
%\end{equation}
%where it is omitted the frequency dependency on the solution $\hat{u}^{(0)}$ for easiness of exposure and used $\Hat{F}(\omega, \mathbf{x})$ as the Fourier transform at frequency $\omega$ of $F(t, \mathbf{x})$.
%Finally, the discretization of (\ref{VectorPDE-Freq}) is defined by selecting a particular array of frequencies $(\omega_i)_{i \in [N_{\omega}]}$ associated to the experimental setup, over which the frequency domain simulations takes place.


\input{../ex_template.tex}

\title{BPP Exercise 4 - Lists and Collections}
\author{A. Hain, M. Nipshagen}
\date{30.04.2018, 8:00}

\makeatletter
\let\thetitle\@title
\let\theauthor\@author
\let\thedate\@date
\makeatother

% Defining the Left Pointy Bracket and the Right Pointy Bracket, so they look nicer
\newcommand\lpb{\small{<}}
\newcommand\rpb{\small{>}}
% sublists are annoying
\newcommand\SubPoint[1]{
  \begin{itemize}
    \item #1
  \end{itemize}
  }

% do not include solutions
% \renewcommand\sol[1]{} \renewcommand\SubPoint[1]{}

\begin{document}

The deadline for this exercise sheet is \textbf{Monday, \thedate.}
%
%\section*{Introductory Words}
%In case we have some information that doesn't directly concern the current exercises.
%
\section{Vector Math}
We can model vectors with tuples and lists. Python however is not equipped with the tools to do vector math, but we can write the functions for this ourselves!\\
Write a script \texttt{vectors.py} which defines the following functions:
\begin{itemize}
  \item \texttt{add(x, y)}: Adds $x$ and $y$ such that the result follows $z_i = x_i + y_i$.
    \cprotect\sol{
\begin{python}
def add(x, y):
      """Adds up the vectors x and y"""
      return [x[i] + y[i] for i in range(len(x))]
\end{python}
    }
  \item \texttt{sub(x, y)}: Subtracts $y$ from $x$ such that the result follows $z_i = x_i - y_i$.
    \cprotect\sol{
\begin{python}
def sub(x, y):
    """returns the result of subtracting y from x"""
		return [x[i] - y[i] for i in range(len(x))]
\end{python}
    }
  \item \texttt{dot(x, y)}: Calculates the scalar (dot) product (or inner product) of $x$ and $y$. The dot product $\lpb x,y\rpb$ is defined as $\lpb x,y\rpb = \sum\limits_{i=1}^{N}x_iy_i$.
\cprotect\sol{\begin{python}
def dot(x, y):
    """Returns the inner product of the two vectors"""
		sum([x[i]y[i] for i in range(len(x))])
	\end{python}}
  \item \texttt{angle(x, y)}: Calculates the angle $\theta$ between the between $x$ and $y$. The angle can be found by using an alternative definition of the dot product: $\lpb x,y\rpb = \|x\|\|y\| \cos\theta$, which we can then solve for $\theta$ and we get $\theta = \arccos\dfrac{\lpb x,y\rpb}{\|x|\|y\|}$.\\
  \emph{Note:} $\|x\|$ where $x$ is a vector is called the vector norm and is calculated by $\sqrt{<x,x>}$. You can find the arccos function in the \texttt{math} package, which we previously used for pi. The function is called \texttt{acos}.
\cprotect\sol{\begin{python}
import math

def angle(x, y):
    """Returns the angle between the two vectors in radien"""
    divisor = math.sqrt(dot(x, x)) * math.sqrt(dot(y, y))
    return math.acos(dot(x, y) / divisor)
	\end{python}}
  \item \texttt{pdist(x, y, **kwargs)}: The distance between the two points $x$ and $y$. Your \textit{kwargs} should recognise the keywords \texttt{metric} and \texttt{p}. Your \texttt{metric} keyword should be able to take one of the values \texttt{'euclidean', 'minkowski', 'cityblock'}, and \texttt{p} can take any integer greater or equal than one. The distance is calculated depending on the metric and should default to \texttt{euclidean}. The distances are calculated as follows:
    \begin{itemize}
      \item \texttt{euclidean}: $d_{euclid} (x,y) = \sqrt[\uproot{2}2]{\sum\limits_{i=1}^N \|x_i-y_i\|^2}$.
      \item \texttt{minkowski}: $d_{minkowsky} (x,y) = \sqrt[\uproot{2}\texttt{p}]{\sum\limits_{i=1}^N \|x_i-y_i\|^\texttt{p}}$.
      \item \texttt{cityblock}: $d_{cityblock} (x,y) = \sum\limits_{i=1}^N \|x_i-y_i\|$\\
      (\emph{Note:} $\|x\|$ is the absolute value.)
    \end{itemize}
    See figure \ref{fig:metrics} for a nicer visualisation.\\
    Don't be afraid of this. It looks scary at first, but it is not beyond the scope of what you already learned.
\cprotect\sol{\begin{python}
import math

def pdist(x, y, **kwargs):
    """
    Calculates the distance between x and  y using the given metric.

    The default metric used for distance calculation is the euclidean metric. Other options are 'cityblock' and 'minkowski'. If using minkowski distance, the parameter p >= 1 can be supplied.
    """
    # check whether metric is given, and use euclidean as default
    metric = kwargs['metric'] if 'metric' in kwargs else 'euclidean'
     if metric == 'minkowski':
        p = kwargs['p'] if 'p' in kwargs else 2
    if metric == 'euclidean':
        squared = [abs(z)**2 for z in sub(x,y)]
        return math.sqrt(sum(squared))
    elif metric == 'cityblock':
        diff = [abs(z) for z in sub(x, y)]
        return sum(diff)
    elif metric == 'minkowski':
        if p < 1:
             return None
        to_p = [abs(z)**p for z in sub(x, y)]
        return sum(to_p) ** (1/p)
    else:
        return None

\end{python}
}
  \item \textbf{BONUS:} \texttt{outer(x, y)}: calculates the outer product of two vectors. The outer product of two vectors is the tensor product of the two. For two vectors with size $n$ the outer product will yield a matrix of size $(n, n)$.
  The outer product is calculated as $C_{i_j} = x_iy_j$.
  \cprotect\sol{\begin{python}
def outer(x, y):
    """Returns a list of lists representinx a matrix calculated from the two vectors, each list represents one row"""
    # one liner:
    # return [[xi * yi for yi in y] for xi in x]
    result = []
    for i in range(len(x)):
        row = []
        for j in range(len(y)):
          row.append(x[i] * y[j])
        result.append(row)
		return result
	\end{python}}
\end{itemize}
You can assume that all vectors have the same size. To verify your function works correctly you can test it with the following values:\\
$a = (1, 2, 3), b = (4, 5, 6), c = [0, 1, 0, 0, 1], d = [1.5, 2.5, 3.5, 4.5, 5.5]$\\
\begin{tabular}{|ll|}
  \hline
  Call & Result \\
  \hline
  \texttt{add(a,b)} & (5, 7, 9)\\
  \texttt{add(b,a)} & (5, 7, 9)\\
  \texttt{sub(a,b)} & (-3, -3, -3)\\
  \texttt{dot(c,d)} & 8.0\\
  \texttt{angle(a,b)} & approx. 0.23\\
  \texttt{pdist(a,b)} & approx. 5.20\\
  \texttt{pdst(a,b, metric='cityblock')} & 9\\
  \texttt{pdist(c,d, metric='minkowski', p=3)} & 6.14\\
  \texttt{outer(a,b)} & $\left[\begin{matrix} 4 & 5 & 6\\ 8 & 10 & 12\\ 12 & 15 & 18 \end{matrix}\right]$\\
  \hline
\end{tabular}
\begin{figure}
  \includegraphics[scale=0.5]{metriken}
  \label{fig:metrics}
  \caption{Blue, red, and yellow are examples for the cityblock distance (it looks like following the streets of a grid city) and green is the euclidean distance.}
  \small{Taken from \url{https://en.wikipedia.org/wiki/Taxicab_geometry#/media/File:Manhattan_distance.svg}}

\end{figure}

\section{Which to What}
We will give you a few examples of datasets. Which collection type would you use to save this data in?\\
Please explain your answers.
\begin{itemize}
\item options a user can click on in a program menu
\SubPoint{\sol{List}}
  \item a country's name, population and capital
    \SubPoint{\sol{Tuple or Dict}}
  \item food ingredients
    \SubPoint{\sol{List}}
  \item data about a music album
    \SubPoint{\sol{Dict}}
  \item people who visit Basic Programming in Python or Scientific Programming in Python
    \SubPoint{\sol{Set}}
  \item IDs of upcoming orders in an online shop
    \SubPoint{\sol{List}}
  \item nicknames and account information in a forum (e-mail address, password, real name [optional], birth date [optional], ...)
    \SubPoint{\sol{Dict}}
\end{itemize}

\section{The Transform}
In the file \texttt{my\_collection.py} you will find two lists defined: \texttt{subjects} and \texttt{attributes}. The first list contains subject ids, wheras the second one contains attributes corresponding to the subject ids. So the subject at index 0 of \texttt{subjects} has the attribute at index 0 of \texttt{attributes} and the subject at index 9 has the attribute at index 9. You get the idea.\\
You may notice that each subject id appears multiple times. Your task now is to create a function to create one dictionary which uses the subject id as a key and a \textit{list} of attributes as the value.
\cprotect\sol{
\begin{python}
# the given lists
all_subjects = [0, 0, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 9, 9]
all_attributes = ['Materialistic', 'Neat', 'Active', 'Welcoming', 'Creative', 'Ambitious', 'Geek', 'Welcoming', 'Neat', 'Creative', 'Geek', 'Quiet', 'Shy', 'Neat', 'Ambitious', 'Adventurous', 'Active', 'Welcoming', 'Adventurous', 'Neat', 'Ambitious', 'Excitable', 'Active', 'Welcoming', 'Quiet', 'Excitable', 'Ambitious', 'Adventurous', 'Quiet', 'Geek', 'Active', 'Spiritual', 'Quiet', 'Excitable', 'Materialistic', 'Geek', 'Welcoming', 'Excitable', 'Adventurous']

# This is the function you need to implement
def clean_up(subjects, attributes):
  """
  This function takes a list of subject ids which correspond to attributes
  in the second list, and forms a dictionary out of them, with the unique
  subject id as the key and a list of their attributes as the corresponding
  value.
  """
  # and as a one-liner:
  # return {sub : attributes[subjects.index(sub):subjects.index(sub)+subjects.count(sub)] for sub in set(subjects)}
  # create the empty dict that we will keep adding the stuff into one by one
  subject_dict = dict()
  # idx is the counter going from 0 to 38
  # using enumerate saves as the line: subj_id = subjects[idx]
  for idx, subj_id in enumerate(subjects):
  # if this is the first time we encounter this subject id, add it to the dict
  # the value is an empty list for now, we will now add all the attributes
    if subj_id not in subject_dict:
      subject_dict[subj_id] = []
    # add the current attribute to the list of the subject
    subject_dict[subj_id].append(attributes[idx])

  return subject_dict

# So nice, tidy and clean.
subject_dict = clean_up(all_subjects, all_attributes)
\end{python}
}
\end{document}


\section{Subcritical flow without a shock over a bump}

This is a subcritical flow over a bump. This test is adapted from Goutal and Maurel~\cite{GM1997}. No shock occurs in this scenario.

Consider a one dimensional domain $[0,25]$ with topography
\begin{equation}
z(x)= \left\{ \begin{array}{ll}
 0.2-0.05\left(x-10\right)^2& ~\textrm{if}\quad 8 \leq x \leq 12\,,\\
 0 & ~\textrm{otherwise}\,,\\
\end{array} \right.
\end{equation}
together with Dirichlet boundary conditions.
Physically, the boundary conditions mean that there is a source of flow upstream at the point $x=0^{-}$ and at the same time there exists a sink of flow downstream at the point $x=25^{+}$\,.

The analytical height is found by solving the Bernoulli equation. The simplified Bernoulli equation is the following cubic equation
\begin{equation}
h^3 + \left(z - \frac{q^2}{2 g H^2} - H \right) h^2 + \frac{q^2}{2 g} = 0\,,
\end{equation}
where $H$ is the upstream height and $q=uh$ is the discharge or $x$-momentum. When the height $h$ has been found, the velocity is computed as $u=q/h$\,.

\subsection{Results}
For our test we consider the initial condition
\begin{equation}
u(x,y,0)=v(x,y,0)=0\,, \quad
w(x,y,0)= 0.2\,,
\end{equation}
and the Dirichlet boundary conditions at $x=0^{-}$ and $25^{+}$ to be
\begin{equation}
[w,hu,hv]=[2, 4.42, 0]\,.
\end{equation}
Representatives of the simulation results are given in the following three figures. Even though we have small discrepancy in the numerical and analytical momenta, these numerical an analytical solutions should agree quite well. Note the vertical scale of the plots (matplotlib may offset the vertical scale, check top-left of figures).

\begin{figure}
\begin{center}
\includegraphics[width=0.9\textwidth]{stage_plot.png}
\end{center}
\caption{Stage results}
\end{figure}

\begin{figure}
\begin{center}
\includegraphics[width=0.9\textwidth]{xmom_plot.png}
\end{center}
\caption{Xmomentum results}
\end{figure}

\begin{figure}
\begin{center}
\includegraphics[width=0.9\textwidth]{xvel_plot.png}
\end{center}
\caption{Xvelocity results}
\end{figure}

\endinput


\chapter{Optimization}
\label{sec:opt}
Executing \textit{FloatingSE} by hand is sufficient to explore some simple
one-off or comparison analyses between a few runs.  OpenMDAO
provides extensive optimization capability, which can give yield richer
and more insightful analyses.

\section{Methodology}
For a full substructure optimization, we begin with the formulation of
a constrained, nonlinear single-objective optimization problem with
mixed-integer design variables,
\begin{equation}
\begin{array}{ll}
  \min & f\left(\mbf{x}\right)\\
  \text{subject to} & \mbf{g}\left(\mbf{x}\right) \leq 0,\\
  \text{and}& \mbf{x} \in \mbf{X} \\
  \end{array}
\end{equation}
where,
\begin{itemize}
\item $\mbf{x}$ is a vector of $n$ \textit{design variables}, the variables that are adjusted in order to
  find the optimal solution (see Table \ref{tbl:designvar});
\item $f(\mbf{x})$ is the nonlinear \textit{objective function}, the
  metric to be minimized by the optimization algorithm;
\item $\mbf{g} (\mbf{x})$ is the vector of \textit{inequality constraints}, the
  set of conditions that the solution must satisfy (see Table
  \ref{tbl:constraints}).  There are no equality constraints;
\item $\mbf{X}$ is the design variable \textit{bounds}, the bracket of
  allowable design variable values.
\end{itemize}

Note that this problem statement imposes no requirements on the types of
variables in $\mbf{x}$.  A mixed-integer solution is desired, where some
design variables are continuous ($x \in \mbb{R}$) and others are
discrete variables that can only take integer values ($x \in
\mbb{Z}$).  An example of an integer design variable in this
application is the number of offset columns or the number of mooring
line connections.

\section{Gradient-Based versus Derivative-Free Algorithms}
Derivative-free optimization algorithms are preferable for substructure
optimization problems for a few reasons, despite their known performance
drawbacks in terms of wall-clock time.  First, to do a complete
configuration optimization of the substructure, a mixed-integer capable
algorithm is required.  No gradient-based optimization algorithm is
capable of handling these types of variables directly (unless a rounding
approximation is used).  A genetic algorithm, properly designed, can
support mixed-integer variables for a global design space optimization.

Another reason for the selection of derivative-free algorithms is that
the \textit{FloatingSE} uses a number of third-party, black box tools or
algorithms that do not come with analytical gradients.  This includes
Frame3DD, MAP++, and some of the API 2U procedures that rely on roots of
nonlinear equations.  Thus, gradient-based optimization algorithms would
be forced to use finite difference approximations around these tools at
the very least.  However, derivatives approximated with finite
differences are expensive to compute accurately.  If computed
inaccurately, for the sake of reducing computational time, finite
difference derivatives can easily lead an optimization algorithm astray,
especially in highly nonlinear or tightly constrained regions of the
design space.  This is another reason for the use of
derivative-free algorithms, even when conducting local neighborhood
design space optimization and/or sensitivity studies.

\section{Design Variables}
In WISDEM, via OpenMDAO, any input parameter can be designated a design
variable.  The design variables used in this study focused on the
geometric specification of the floating substructure and mooring
subsystem.  Slightly different design variables and bounds were used for
spar, semisubmersible, and TLP optimizations.  The complete listing of
the design variables for each optimization configuration is shown in
Table \ref{tbl:designvar}.  Note that the integer design variables were
only used in the global optimization with the genetic algorithm, not the
local search with the simplex algorithm.

\begin{table}[htbp] \begin{center}
    \caption{Standard design variables, their size, and units used for
      optimization in \textit{FloatingSE}.  Note that $n_s$ denotes the
      number of sections in the column discretization.}
    \label{tbl:designvar}
{\footnotesize
  \begin{tabular}{ l l c l c } \hline
    \textbf{Variable} & \textbf{Name} & \textbf{Units} & \textbf{Type} & \textbf{Bounds} \\ \hline \hline
    Main col section height &\mytt{main\_section\_height}& \unit{$m$} & Float array ($n_s$) & 0.1--50 \\
    Main col outer diameter &\mytt{main\_outer\_diameter}& \unit{$m$} & Float array ($n_s+1$) &2.1--40 \\
    Main col wall thickness &\mytt{main\_wall\_thickness}& \unit{$m$} & Float array ($n_s+1$)  &0.001--0.5 \\
    Main col freeboard & \mytt{main\_freeboard}& \unit{$m$} & Float scalar &0--50 \\
    Main col stiffener web height &\mytt{main\_stiffener\_web\_height}& \unit{$m$} & Float array ($n_s$) &0.01--1 \\
    Main col stiffener web thickness &\mytt{main\_stiffener\_web\_thickness}& \unit{$m$} & Float array ($n_s$) &0.001--0.5 \\
    Main col stiffener flange width &\mytt{main\_stiffener\_flange\_width}& \unit{$m$} & Float array ($n_s$) &0.01--5 \\
    Main col stiffener flange thickness &\mytt{main\_stiffener\_flange\_thickness}& \unit{$m$} & Float array ($n_s$) &0.001--0.5 \\
    Main col stiffener spacing &\mytt{main\_stiffener\_spacing}& \unit{$m$} & Float array ($n_s$) &0.1--100 \\
    Main col permanent ballast height &\mytt{main\_permanent\_ballast\_height}& \unit{$m$} & Float scalar &0.1--50 \\
    Main col buoyancy tank diameter &\mytt{main\_buoyancy\_tank\_diameter}& \unit{$m$} & Float scalar &0--50 \\
    Main col buoyancy tank height &\mytt{main\_buoyancy\_tank\_height}& \unit{$m$} & Float scalar &0--20 \\
    Main col buoyancy tank location (fraction) &\mytt{main\_buoyancy\_tank\_location}&& Float scalar &0--1 \\
    \hline
    Number of offset cols &\mytt{number\_of\_offset\_columns}&& Integer scalar & 3-5 \\
    Offset col section height &\mytt{offset\_section\_height}& \unit{$m$} & Float array ($n_s$) &0.1--50\\
    Offset col outer diameter &\mytt{offset\_outer\_diameter}& \unit{$m$} & Float array ($n_s+1$)&1.1--40\\
    Offset col wall thickness &\mytt{offset\_wall\_thickness}& \unit{$m$} & Float array ($n_s+1$) &0.001--0.5\\
    Offset col freeboard & \mytt{offset\_freeboard}& \unit{$m$} & Float scalar &2--15 \\
    Offset col stiffener web height &\mytt{offset\_stiffener\_web\_height}& \unit{$m$} & Float array ($n_s$) &0.01--1\\
    Offset col stiffener web thickness &\mytt{offset\_stiffener\_web\_thickness}& \unit{$m$} & Float array ($n_s$) & 0.001--0.5\\
    Offset col stiffener flange width &\mytt{offset\_stiffener\_flange\_width}& \unit{$m$} & Float array ($n_s$) & 0.01--5\\
    Offset col stiffener flange thickness &\mytt{offset\_stiffener\_flange\_thickness}& \unit{$m$} & Float array ($n_s$) & 0.001--0.5\\
    Offset col stiffener spacing &\mytt{offset\_stiffener\_spacing}& \unit{$m$} & Float array ($n_s$) &0.01--100\\
    Offset col permanent ballast height &\mytt{offset\_permanent\_ballast\_height}& \unit{$m$} & Float scalar &0.1--50\\
    Offset col buoyancy tank diameter &\mytt{offset\_buoyancy\_tank\_diameter}& \unit{$m$} & Float scalar &0--50 \\
    Offset col buoyancy tank height &\mytt{offset\_buoyancy\_tank\_height}& \unit{$m$} & Float scalar &0--20 \\
    Offset col buoyancy tank location (fraction) &\mytt{main\_buoyancy\_tank\_location}&& Float scalar & 0--1 \\
    Radius to offset col &\mytt{radius\_to\_offset\_column}& \unit{$m$} & Float scalar &5--100 \\
    \hline
    Pontoon outer diameter &\mytt{pontoon\_outer\_diameter}& \unit{$m$} & Float scalar &0.1--10 \\
    Pontoon wall thickness &\mytt{pontoon\_wall\_thickness}& \unit{$m$} & Float scalar &0.01--1 \\
    Lower main-offset pontoons &\mytt{lower\_attachment\_pontoons\_int}&& Integer scalar & 0--1 \\
    Upper main-offset pontoons &\mytt{upper\_attachment\_pontoons\_int}&& Integer scalar & 0--1 \\
    Cross main-offset pontoons &\mytt{cross\_attachment\_pontoons\_int}&& Integer scalar & 0--1 \\
    Lower offset ring pontoons &\mytt{lower\_ring\_pontoons\_int}&& Integer scalar & 0--1 \\
    Upper offset ring pontoons &\mytt{upper\_ring\_pontoons\_int}&& Integer scalar & 0--1 \\
    Outer V-pontoons &\mytt{outer\_cross\_pontoons\_int}&& Integer scalar & 0--1 \\
    Main col pontoon attach lower (fraction) &\mytt{main\_pontoon\_attach\_lower}&& Float scalar & 0--0.5\\
    Main col pontoon attach upper (fraction) &\mytt{main\_pontoon\_attach\_upper}&& Float scalar & 0.5--1\\
    \hline
    Fairlead (fraction) &\mytt{fairlead\_location}&& Float scalar &0--1 \\
    Fairlead offset from col &\mytt{fairlead\_offset\_from\_shell}& \unit{$m$} & Float scalar & 5--30\\
    Fairlead pontoon diameter &\mytt{fairlead\_support\_outer\_diameter}& \unit{$m$} & Float scalar & 0.1--10 \\
    Fairlead pontoon wall thickness &\mytt{fairlead\_support\_outer\_thickness}& \unit{$m$} & Float scalar &0.001--1 \\
    Number of mooring connections &\mytt{number\_of\_mooring\_connections}&& Integer scalar &3--5 \\
    Mooring lines per connection &\mytt{mooring\_lines\_per\_connection}&& Integer scalar &1--3 \\
    Mooring diameter &\mytt{mooring\_diameter}& \unit{$m$} & Float scalar &0.05--2 \\
    Mooring line length &\mytt{mooring\_line\_length}& \unit{$m$} & Float scalar &0--3000 \\
    Anchor distance &\mytt{anchor\_radius}& \unit{$m$} & Float scalar &0--5000 \\
  \hline \end{tabular}
}
\end{center} \end{table}

\section{Constraints}
Due to the many design variables, permutations of settings, and applied
physics, there are many constraints that must be applied for an
optimization to close.  The constraints capture both physical
limitations, such as column buckling, but also inject industry
standards, guidelines, and lessons learned from engineering experience
into the optimization.  As described in Section \ref{sec:intro}, this is
a critically important element in building a MDAO framework for
conceptual design that yields feasible results worth interrogating
further with higher-fidelity tools.  The constraints used in the
substructure design optimization and sensitivity studies are listed in
Table \ref{tbl:constraints}.  Where appropriate, some of the constraint
values differ from one type of substructure to another.  Some additional
explanation is provided for a handful of constraints in the subsections
below.

\begin{table}[htbp] \begin{center}
    \caption{Optimization constraints used in \textit{FloatingSE}.}
    \label{tbl:constraints}
    {\footnotesize
  \begin{tabular}{ c l c l} \hline
    \textbf{Lower} & \textbf{Variable} & \textbf{Upper} & \textbf{Comments}\\
\hline \hline
 & \textbf{Tower / Main / Offset Columns} &  & \\
 & Eurocode global buckling & 1.0 & \\
 & Eurocode shell buckling & 1.0 & \\
 & Eurocode stress limit & 1.0 & \\
  & Manufacturability & 0.5 & Taper ratio limit\\
  120.0 & Weld-ability &  & Diameter:thickness ratio limit\\
\hline & \textbf{Main / Offset Columns} &  & \\
 & Draft ratio & 1.0 & Ratio of draft to max value\\
 & API 2U general buckling- axial loads & 1.0 & \\
 & API 2U local buckling- axial loads & 1.0 & \\
 & API 2U general buckling- external loads & 1.0 & \\
 & API 2U local buckling- external loads & 1.0 & \\
 & Wave height:freeboard ratio & 1.0 & Maximum wave height relative to freeboard\\
  1.0 & Stiffener flange compactness &  & \\
  1.0 & Stiffener web compactness &  & \\
 & Stiffener flange spacing ratio & 1.0 & Stiffener spacing relative to flange width\\
 & Stiffener radius ratio & 0.50 & Stiffener height relative to diameter\\
\hline & \textbf{Offset Columns} &  & \textit{Semi only}\\
  0.0 & Heel freeboard margin &  & Height required to stay above waterline at max heel\\
  0.0 & Heel draft margin &  & Draft required to stay submerged at max heel\\
\hline & \textbf{Pontoons} &  & \textit{Semi only}\\
 & Eurocode stress limit & 1.0 &\\
\hline & \textbf{Tower} &  & \\
  -0.01 & Hub height error & 0.01 &\\
\hline & \textbf{Mooring} &  & \\
  0.0 & Axial stress limit & 1.0 &\\
 & Line length limit & 1.0 & Loss of tension or catenary hang\\
 & Heel moment ratio & 1.0 & Ratio of overturning moment to restoring moment\\
 & Surge force ratio & 1.0 & Ratio of surge force to restoring force\\
\hline & \textbf{Geometry} &  & \\
  1.0 & Main-offset spacing &  & Minimum spacing between main and offset columns \\
  0.0 & Nacelle transition buffer &  & Tower diameter limit at nacelle junction\\
  -1.0 & Tower transition buffer & 1.0 & Diameter consistency at freeboard point\\
\hline & \textbf{Stability} &  & \\
  0.10 & Metacentric height &  & \textit{Not applied to TLPs}\\
  1.0 & Wave-Eigenmode boundary (upper) &  & Natural frequencies below wave frequency range\\
 & Wave-Eigenmode boundary (lower) & 1.0 & Natural frequencies above wave frequency range\\
  0.0 & Water ballast height limit & 1.0 & \\
  0.0 & Water ballast mass &  & Neutral buoyancy\\
    \hline \end{tabular}
  }
\end{center} \end{table}

\subsection{Geometry Constraints}
Words
%
\begin{table}[htbp] \begin{center}
    \caption{Constraint variables for the geometry in \textit{FloatingSE}.}
    \label{tbl:geomconvar}
{\footnotesize
  \begin{tabular}{l l l } \hline
    \textbf{Variable} & \textbf{Type} & \textbf{Description} \\
    \mytt{max\_draft} & Float scalar & Maximum allowable draft for the substructure\\
  \hline \end{tabular}
}
\end{center} \end{table}

\subsection{Manufacturing Constraints}
Manufacturing steel frustum shells requires rolling steel plates into
shape and welding along a seam to close the section.  To accommodate
traditional rolling and welding practices, both the diameter taper over
the course of a section and the wall thickness ratio relative to the
diameter are capped.  Similarly, to facilitate welding the
semisubmersible pontoons to the columns, constraints regarding the radio
of diameters between the two are enforced. These limits are determined
by user parameters in Table \ref{tbl:manconvar} and constraints,
%
\begin{table}[htbp] \begin{center}
    \caption{Constraint variables for the manufacturability in \textit{FloatingSE}.}
    \label{tbl:manconvar}
{\footnotesize
  \begin{tabular}{l l l } \hline
    \textbf{Variable} & \textbf{Type} & \textbf{Description} \\
    \mytt{min\_taper\_ratio} & Float scalar & For manufacturability of rolling steel\\
    \mytt{min\_diameter\_thickness\_ratio} & Float scalar & For weld-ability\\
    \mytt{connection\_ratio\_max} & Float scalar & For welding pontoons to columns\\
  \hline \end{tabular}
}
\end{center} \end{table}

\subsection{Stress Limits and Code Compliance}
The stress and buckling code compliance constraints are formulated as
utilization ratios (ratio of actual to maximum values), with a safety
factor, which must be less than one. The safety factor parameters are
listed in Table \ref{tbl:safetyvar}.
%
\begin{table}[htbp] \begin{center}
    \caption{Variables specifying the factors of safety within \textit{FloatingSE}.}
    \label{tbl:safetyvar}
{\footnotesize
  \begin{tabular}{ l l l } \hline
    \textbf{Variable} & \textbf{Type} & \textbf{Description} \\
    \mytt{gamma\_f} & Float scalar & Safety factor on \\
    \mytt{gamma\_b} & Float scalar & Safety factor on buckling\\
    \mytt{gamma\_m} & Float scalar & Safety factor on materials\\
    \mytt{gamma\_n} & Float scalar & Safety factor on consequence of failure\\
    \mytt{gamma\_fatigue} & Float scalar & Not currently used\\
  \hline \end{tabular}
}
\end{center} \end{table}

\subsection{Stability}
As described above, surge and pitch stability are enforced through
similar approaches.  The total force and moment acting on the turbine
are compared to the restoring forces and moments applied by the mooring
system, buoyancy, or other sources at the maximum allowable point of
displacement.  These constraints are formulated as ratios with the user
specifying the maximum allowable limits via the variables in Table
\ref{tbl:moorcon}.
%
\begin{table}[htbp] \begin{center}
    \caption{Constraint variables for the mooring system in \textit{FloatingSE}.}
    \label{tbl:moorcon}
{\footnotesize
  \begin{tabular}{ l l c l } \hline
    \textbf{Variable} & \textbf{Type} & \textbf{Units} & \textbf{Description} \\
    \mytt{max\_offset} & Float scalar & $m$& Max surge/sway offset \\
    \mytt{operational\_heel} & Float scalar & $deg$& Max heel (pitching) angle in operating conditions \\
    \mytt{max\_survival\_heel} & Float scalar & $deg$& Max heel (pitching) angle in parked conditions \\
  \hline \end{tabular}
}
\end{center} \end{table}

\section{Objectives}
Different anaylses will emphasize different metrics, requiring different
objective functions.  Under the default assumption that the user wishes
to minimize cost and adhere to stability constraints, the objective
function would be total substructure cost (variable name,
\texttt{total\_cost}) or mass (variable name, \texttt{total\_mass}).

\section{Example}

\begin{figure}[htb]
  \begin{subfigure}[b]{0.29\linewidth}
    \centering \includegraphics[width=\linewidth]{figs/spar-cost1.png}
    \caption{Spar}
  \end{subfigure}
  \begin{subfigure}[b]{0.39\linewidth}
    \centering \includegraphics[width=\linewidth]{figs/semi-mass2.png}
    \caption{Semisubmersible}
  \end{subfigure}\\
  \begin{subfigure}[b]{0.29\linewidth}
    \centering \includegraphics[width=\linewidth]{figs/tlp-cost2.png}
    \caption{Spar}
  \end{subfigure}
  \caption{Examples of optimized spar, semisubmersible, and TLP geometries.}
  \label{fig:optex}
\end{figure}