% !TEX encoding = UTF-8 Unicode

\documentclass[a4paper]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{xcolor}
\usepackage{pgffor} %provides the command \foreach
\usepackage{mathtools} %provides \clap and mathmode versions of \mathrlap, \mathllap, and \mathclap

\newcommand{\bs}[1]{{\rmfamily\color{blue}\textbackslash{}#1}}

\newenvironment{example}[1]{%
\vspace{10pt}
\noindent\textbf{#1}\sffamily\par\vspace{10pt}%
}
{%
\par\vspace{10pt}
}

\newlength{\glyphwd}
\newcommand{\bx}[1]{%
  \bgroup
  \settowidth\glyphwd{#1}%
  \setlength{\fboxrule}{0.1pt}% hairline
  \setlength{\fboxsep}{-0.05pt}%
  \makebox[0pt][l]{\vrule height 0.05pt depth 0.05pt width \glyphwd}%
  \fbox{#1}%
  \egroup
}

\title{A Glimpse on Advanced \LaTeX{}}
\author{J.M. Pérez Pardo}
\date{}

\begin{document}

\maketitle

\tableofcontents

\section{How \LaTeX\ prints glyphs on a page}

Before we answer this question we are going to look at how did a printing press (J. Gutenberg ~1400a.d.) work. The glyphs were molded in small metals blocks like those appearing in Figure~\ref{fig:metalblockschase}. These blocks were used to compose a page by inserting them in a wooden chase, see Figure \ref{fig:metalblockschase}. First building words and then lines. The full chase was then covered with ink and introduced in the \emph{press} to print a page.
%
\begin{figure}[h]
  \hfil\vbox{ \hbox{\includegraphics[width=.5\textwidth]{glympse_figures/metal_blocks.jpg}} \vspace{1cm}}\hskip 0pt plus 0.5fil \includegraphics[width=.4\textwidth]{glympse_figures/chase.jpg}\hfil
  \caption{\emph{Left}: Metal blocks and chase used in a printer press. \emph{Right}: Chase where the metal blocks are inserted}\label{fig:metalblockschase}
\end{figure}
%

\TeX\ (and \LaTeX{}.) does actually a very similar thing to compose a document. Each glyph is contained in an invisible container called \emph{box} that has a rectangular shape. This box has given dimensions, \emph{width}, \emph{height} and \emph{depth} and determines how much space does it take. The \emph{ink} of the glyph is adjusted with respect to the box. The ink might even lie outside of the box. Actually \TeX\ does not care about the ink. All that matters to it are the boxes and their alignment. How the ink is placed with respect to the box is decided by the persons how designed the different fonts. When parsing the document, \TeX\ construct words putting all these boxes together and building bigger boxes.

\section{Boxes}

A box is a rectangular shaped object that has three numbers (also called dimensions) associated to it, \emph{width}, \emph{height} and \emph{depth}. These dimensions determine how big a box is and what its relative position to neighboring boxes will be.  The structure of a box can be seen in Figure~\ref{fig:box}. The baseline determines the imaginary line where characters lie. The height determines how high a character lies above the baseline and the depth determines how much it \emph{hangs} from the baseline. For instance, the box of the glyph ``h'' has a bigger height than the box of the glyph ``a'' and both of them have 0 depth. The box of the glyph ``g'' has the same height than the box of the glyph ``a'' but non-zero depth.
%
\begin{figure}[h]
  \hfil\includegraphics[width=.7\textwidth]{glympse_figures/box.png}\hfil
  \caption{A box and its dimensions. \emph{Source}: The \TeX{}book \cite{Knuth1990}\label{fig:box}}
\end{figure}

The macro \bs{bx} defined in the preamble displays the margins of the boxes so that we can have a look at the dimensions directly:\\

\hfil\foreach \i in {x, M, f, g, ), p, {\itshape f}}{\bx{\i}\hfil}\\

\noindent Actually these are too small to be appreciated in depth so I will use a larger font. This is done with the \bs{Huge} command.\\

\hfil\foreach \i in {x, M, f, g, ), p, {\itshape f}}{\bx{\Huge \i}\hfil}\\

\noindent Notice that ``x'', ``M'', ``f'' have no depth while ``g'', ``)'', ``p'', ``\textit{f}'' have. In addition, notice that the ink of the italic shape of the letter ``f'' lies outside the box. This is something usual in italic fonts. Otherwise the characters in a word would be too separated from each other. Notice also how each character has a different width.

\section{Horizontal and vertical modes. How \LaTeX{} puts boxes together and prints pages.}

Now that we know how \LaTeX{} understands each character we are going to get an idea of how it does to build the page. When producing the document the source file is split into text units which are paragraphs. Each paragraph will end up being a paragraph in the final document. When the parser begins reading a paragraph it knows that the paragraph ends when a \bs{par} command is found. This might be the first time that we see this command because it is rarely typed in the source code. The reason is that a blank line in the source code, two end of line characters with possibly white spaces between them, is interpreted automatically like the \bs{par} command. The next two paragraphs are an example of this. Check the source code. There is no blank line in between the next two paragraphs but a \bs{par} command.

\begin{example}{Two paragraphs separated by a \bs{par}}
No one expects the Spanish Inquisition! Our chief weapon is surprise, fear and surprise; two chief weapons, fear, surprise, and ruthless efficiency! [a \bs{par} command is here and no blank line]\par Er, among our chief weapons are: fear, surprise, ruthless efficiency, and near fanatical devotion to the Pope! Um, I'll come in again
\end{example}

Whenever a paragraph starts or ends several things happen. There are some obvious formatting operations that occur, like adding the indentation on the first line of including extra space between the first line of a paragraph and the last line of the previous one. But there are many other things that occur internally and we will give a brief description of what happens with them. Before a paragraph starts the parser is in the so called \emph{vertical mode}. When the parser meets the first character of a paragraph it switches to horizontal mode and starts putting boxes together. First it collects all the non-white space characters that he finds up to the next white space character. The boxes are aligned at their reference points, so that they share the baseline. Once the word is complete a new box is defined that has height and depth the biggest height and depth of the boxes that compose it, and width the total sum of the widths of all the boxes. This is illustrated next with the word ``Perspective''.\\

\noindent\hfil\includegraphics{glympse_figures/word.pdf}\hfil\includegraphics{glympse_figures/word_boxed.pdf}\hfil\\

\noindent The different boxes of the words are then put together. Between the words, white space is added. As you can see in the example below white space is not a box of a given width without ink. This white space is called \emph{glue} and is what allows \TeX{} to print the justified blocks of text. We will speak about \emph{glue} later.\\

\noindent\hfil\includegraphics{glympse_figures/sentence.pdf}\hfil\\

\noindent \TeX{} will continue to do so until it has finished parsing the full paragraph. At this time what \TeX{} has is a very long line representing the paragraph. It is now time to break the paragraph into lines. The \emph{glue}, i.e., the white space between words, has not a fixed length but instead can stretch or shrink to make the lines exactly as long as needed. \TeX{} has a complicated algorithm, cf. \cite[Chapter~14]{Knuth1990}, to decide where are the optimal points to break the paragraph into lines such that the outcome is as visually pleasant as possible. We are not going to enter in the details of this algorithm but at the end of this section we will discuss some basic things that will allow us to tune how it works.
After the paragraph is broken into lines the parser goes into \emph{vertical mode}. This time, the boxes that make the lines are put vertically one after the other and there is also some \emph{glue} inserted between these boxes. You can get an idea with the following picture.\\

\noindent\hfil\includegraphics{glympse_figures/paragraph_boxed.pdf}\hfil\\

\noindent All that is missing is to stretch the glue to make all line boxes have the same length. The parser continues then in \emph{vertical mode} until the next paragraph starts. When there are enough lines to fit a page it is \emph{shipped} for printing. In principle \TeX{} could  use a similar algorithm than it uses for breaking a paragraph into lines to split the document into pages but it doesn't. When the lines have enough length to fit the page they are stretched or shrunk for the best output and the page is closed for shipping. This was done so because of memory considerations. Notice that the full document should be in memory to accomplish this and for a very large document this could be a problem.

We are going to give now some hints in how the paragraph breaking algorithm works. The fundamental idea is that breaking the paragraph at a point has a cost. This was called by D.E.~Knuth the \emph{badness}. The algorithm considers many possibilities of breaking the paragraph into lines and chooses the one with the minimum \emph{badness}. This works roughly as follows. If a line has to be stretched or shrunk to fit the page it gets a \emph{penalty} depending on how much it had to be stretched or shrunk. Other operations like hyphenating a word also have a \emph{penalty} and so on. The interesting thing about this is that penalties can be set by hand to force or prevent \TeX{} to take a line break. This is done with the \bs{penalty} command. Normally you do not need to take care about this but on occasions you might feel that a certain break is not appropriate and we will see what can be done in those cases. Typical penalties handled by \TeX{} are in a range between 10 and 10. A penalty of 10000  (\bs{penalty 10000}) or more is considered to be so large that \TeX{} will never break there. Penalties can be negative too. This makes certain breakpoints to be more desirable than others as the total badness will be diminished if the break point happens there. A penalty of -10000 (\bs{penalty -10000}) is considered to be so low that \TeX{} will always break there.\\

\begin{example}{A paragraph to be used as reference to see the effect of adding penalties.}
No one expects the Spanish Inquisition! Our chief weapon is surprise, fear and surprise; two chief weapons, fear, surprise, and ruthless efficiency! Er, among our chief weapons are: fear, surprise, ruthless efficiency, and near fanatical devotion to the Pope! Um, I'll come in again\dots
\end{example}

\noindent As you can see the points that have been chosen by \TeX{} to break the lines are after the words ``and'', ``our'', and ``to''. The next paragraph has a penalty of 10000 after the word ``our''.

\begin{example}{The paragraph above with a penalty of 10000 after the word ``our''}
No one expects the Spanish Inquisition! Our chief weapon is surprise, fear and surprise; two chief weapons, fear, surprise, and ruthless efficiency! Er, among our{\penalty10000} chief weapons are: fear, surprise, ruthless efficiency, and near fanatical devotion to the Pope! Um, I'll come in again\dots
\end{example}

\noindent You can see that the break didn't occur after the word ``our'' but there were more changes in the paragraph. To avoid stretching that line too much \TeX{} changed the breaks of the other lines too. We want to keep the ``and'' as the breaking point of the first paragraph so let us add a penalty of -10000 after the ``and'' and see what happens.

\begin{example}{The paragraph above with a penalty of 10000 after the word ``our'' and a penalty of -10000 after the word ``and''}
No one expects the Spanish Inquisition! Our chief weapon is surprise, fear and{\penalty-10000} surprise; two chief weapons, fear, surprise, and ruthless efficiency! Er, among our{\penalty10000} chief weapons are: fear, surprise, ruthless efficiency, and near fanatical devotion to the Pope! Um, I'll come in again\dots
\end{example}

\noindent This time the white space of the second line was stretched a lot to fit the line width. Notice that not all white spaces were stretched by the same amount\dots We will understand why this is so when we learn about glue in the next section. Let us consider a final example with a penalty -10000 after the word ``fear,'', that is, about at the middle of one optimal line.

\begin{example}{The paragraph above with a penalty of -10000 after the word ``fear,''.}
No one expects the Spanish Inquisition! Our chief weapon is surprise, fear and surprise; two chief weapons, fear,{\penalty-10000} surprise, and ruthless efficiency! Er, among our chief weapons are: fear, surprise, ruthless efficiency, and near fanatical devotion to the Pope! Um, I'll come in again\dots
\end{example}

\noindent As expected we are forcing a line break there, but the line is stretched by a fairly large amount. Actually, this is almost what \TeX{} to force a line break when one types \bs{\bs{ }}, but the stretching needs to be corrected.

\section{The \emph{glue} and spacing in \LaTeX}

All the spacing commands in \LaTeX{} are related with \emph{glue}. When parsing the document any amount of spaces between characters is substituted by \emph{glue} and a single end of line character is transformed by the parser into a white space and therefore also \emph{glue}. Actually the name \emph{glue} is not very descriptive of what it does and the name \emph{spring} would be more appropriate. This is how D.E.~Knuth puts it: ``\emph{Once you understand \TeX{}’s concept of glue, you may well decide that it was misnamed; real glue doesn’t stretch or shrink in such ways, nor does it contribute much space between boxes that it welds together. Another word like ``spring'' would be much closer to the essential idea, since springs have a natural width, and since different springs compress and expand at different rates under tension. But whenever the author has suggested changing \TeX{}’s terminology, numerous people have said that they like the word “glue” in spite of its inappropriateness; so the original name has stuck.}''

There are two types of \emph{glue}. One for the horizontal mode and one for the vertical mode. The primitive \TeX{} commands for including them are \bs{hskip} and \bs{vskip}. They add glue respectively in the horizontal and the vertical mode. Glue accepts three parameters, which must be \emph{dimensions}. That is a number following a unit of measure like \texttt{pt} (points), \texttt{cm} (centimeters), \texttt{ex} (the width of a small x in the current font), \texttt{em} (the width of a capital M in the current font) and others.\\

\bs{hskip}{\ttfamily~<\textsf{\itshape dimen}> plus <\textsf{\itshape dimen}> minus <\textsf{\itshape dimen}>}

\bs{vskip}{\ttfamily~<\textsf{\itshape dimen}> plus <\textsf{\itshape dimen}> minus <\textsf{\itshape dimen}>}\\

\noindent The first dimension gives the fix space that the glue will take. The second dimension, after the ``plus'', determines how much it can stretch and the third one, after the ``minus'', how much it can shrink. For example, in the source code you could write\\

{\ttfamily WORD \bs{hskip} 2em plus 1ex minus 2pt WORD}\\

Which results in\\

WORD \hskip 2em plus 1ex minus 2pt WORD \\

This means that each \emph{glue} between words has a determined amount of stretchability or shrinkability. When a box has to be stretched (or shrunk) each glue in it adds (or substracts) to each fixed length a quantity proportional to its glue plus (minus) dimension to get the desired length. For instance, after punctuation marks the \emph{glue} is more stretchable than between words and so is \emph{glue} after a dot than after a comma. This explains the behaviour of the stretching in the examples of the previous section.

In addition to the dimensions mentioned above, \TeX{} has defined \textbf{three different types of infinity}. Each one of them is infinitely larger than the previous one. These are called \texttt{fil}, \texttt{fill} and \texttt{filll} in increasing order of infinity. These infinities can be used as the dimension of the stretching or shrinking quantity in \emph{glue}. In essence they provide an infinite amount of stretchability that fills the line, justifying their name. Below some examples on how this works.

\begin{example}{Using \emph{glue} with infinite stretchability}
Below we have several examples. There is a line with the source code and directly below it is the output that it produces.\\

\verb!word \hskip 0pt plus 1fil minus 0pt word!:

word \hskip 0pt plus 1fil minus 0pt word\\

\verb!word \hskip 0pt plus 1fill minus 0pt word!:

word \hskip 0pt plus 1fill minus 0pt word\\

\verb!word \hskip 0pt plus 1filll minus 0pt word!:

word \hskip 0pt plus 1filll minus 0pt word\\

\verb!word \hskip 0pt plus 1fill  word  \hskip 0pt plus 1fill word!:

word \hskip 0pt plus 1fill  word  \hskip 0pt plus 1fill word\\

\verb!word \hskip 0pt plus 1fill  word  \hskip 0pt plus 2fill word!:

word \hskip 0pt plus 1fill  word  \hskip 0pt plus 2fill word\\

\verb!word \hskip 0pt plus 1filll  word  \hskip 0pt plus 10fill word!:

word \hskip 0pt plus 1filll  word  \hskip 0pt plus 10fill word\\

\end{example}

We can see that a greater infinity type neglects the presence of lower infinities. Infinities of the same type will be weighted according to the amount of it in the line. There is just one point that should raise our attention tight now. Why doesn't the infinite stretchability of the first example push the right word to the end of the line like in the other cases? The answer has to do with what \TeX{} does at the end of a paragraph to prevent the last line to stretch. At the end of a paragraph automatically an ``\bs{hskip} {\ttfamily 0pt plus~1fil minus~0pt}'' is inserted to keep the line short. The second word is pushed at its two sides by equally weighted infinite \emph{glue}. That is why it remains near the middle of the line.

There are some macros which are shorthand for this infinite stretchable \emph{glue}. For instance \bs{hfil} is defined as \bs{hskip} {\ttfamily 0pt plus~1fil minus~0pt} and equivalently \bs{hfill}, \bs{vfil} and \bs{vfill}. There is no macro for the greatest infinity because it is rarely used. There are also macros to define fixed, i.e., non stretchable/shrinkable \emph{glue}. These are \bs{hspace}\{<\textsf{\itshape dimen}>\} and \bs{vspace}\{<\textsf{\itshape dimen}>\}. The former is defined by \bs{hskip}{\ttfamily~<\textsf{\itshape dimen}> plus~0pt minus~0pt} and the latter is defined equivalently. In this document I have used these macros and also some \emph{glue} to tune the adjustment of the figures. Have a look at them in the source file to see what effect they had in the final layout.

There is still one important  thing to discuss and is that vertical \emph{glue} takes effect only during the vertical mode. When \TeX{} is in horizontal mode and encounters a \bs{vspace} command it is not inserted immediately but after the line that contains it and will be used in vertical mode to spread the lines. Check the following example where a \bs{vspace} command is used in the middle of the paragraph. Intuitively one would expect that after the command the rest of the text would have been shifted, but this is not what happens.

\newpage\begin{example}{A \bs{vspace}\{1cm\} is inserted after ``Inquisition!''}
No one expects the Spanish Inquisition!\vspace{1cm}Our chief weapon is surprise, fear and surprise; two chief weapons, fear, surprise, and ruthless efficiency!

Er, among our chief weapons are: fear, surprise, ruthless efficiency, and near fanatical devotion to the Pope! Um, I'll come in again\dots
\end{example}

To prevent this behaviour use vertical \emph{glue} at the beginning or end of a paragraph, or between paragraphs.

\section{Special commands to manipulate boxes}

It is time know to learn some commands that allow to manipulate boxes. Knowing this allows for fine tuning of placement, in particular in formulas. \LaTeX{} does a great job at typesetting but not all the cases are covered by the programers and many cases need to be adjusted by hand. Many of these situations can be addressed easily by knowing the following commands. In addition, they can be used to defined many useful macros that can be adapted to many situations. We will learn this in the examples. Remember that arguments in square brackets represent optional arguments, they might be given or not.  Each command comes with some examples. The boxes are typeset using the \bs{bx} command defined in the preamble. They would not be seen otherwise.

\begin{description}
  \item[\bs{hbox}\{contents\}] This is a \TeX{} primitive. It creates a box with the contents parsed in \emph{horizontal mode}. It should be avoided in favour of \bs{mbox} except in special situations. This box is unbreakable once created.\\ Example: \verb!\hbox{Hello}!

  \bx{\hbox{Hello}}

  \item[\bs{vbox}\{contents\}] This is a \TeX{} primitive. It creates a box with the contents parsed in \emph{vertical mode}. Should be used in situations when one wants to put one box on top of other box. The minipage environment should be used instead of this one. \\ Example: \verb!\vbox{a\\b\\c} \vbox{\hbox{a}\hbox{b}\hbox{c}}!

   \bx{\vbox{a\\b\\c}} \bx{\vbox{\hbox{a}\hbox{b}\hbox{c}}}

  \item[\bs{mbox}\{contents\}] Essentially like \bs{hbox} with more predictable behaviour. \\ Example: \verb!\mbox{Hello}!

  \bx{\mbox{Hello}}

  \item[\bs{makebox}{[}width{]}{[}alignment{]}\{contents\}] Like \bs{mbox} but defines a box with given width. The contents can be aligned l,c or r.\\ Example: \verb!\makebox[1em][r]{Hello} \makebox[5em][r]{Hello}!

  \bx{\makebox[1em][r]{Hello}} \bx{\makebox[5em][r]{Hello}}

  \verb!\makebox[5em][c]{Hello} \makebox[5em][l]{Hello} \makebox[1em][l]{Hello}!

   \bx{\makebox[5em][c]{Hello}} \bx{\makebox[5em][l]{Hello}} \bx{\makebox[1em][l]{Hello}}

    \item[\bs{newsavebox}\{\bs{name}\}] Creates a \emph{register}, that is, a bin, where one can save a box.

  \item[\bs{sbox}\{\bs{name}\}\{contents\}] Creates a box in horizontal mode and saves it in a register (bin) with name \bs{name} that was previously created with \bs{newsavebox}.\\ Example:
  \begin{verbatim}
    \newsavebox{\mybox}
    \sbox{\mybox}{Hello}
    The width of \bs{mybox} is \mbox{\the\wd\mybox}.
    The height of \bs{mybox} is \mbox{\the\ht\mybox}.
    The depth of \bs{mybox} is \mbox{\the\dp\mybox}.
  \end{verbatim}

  \newsavebox{\mybox}
  \sbox{\mybox}{Hello}
  The width of \bs{mybox} is \mbox{\the\wd\mybox}.
  The height of \bs{mybox} is \mbox{\the\ht\mybox}.
  The depth of \bs{mybox} is \mbox{\the\dp\mybox}.

  \item[\bs{savebox}{[}width{]}{[}alignment{]}\{\bs{name}\}\{contents\}] Like \bs{sbox} but adjust the width an alignment like \bs{makebox}.

  \item[\bs{usebox}\{\bs{name}\}] Prints the box in the register \bs{name}.\\ Example: \verb!\usebox{\mybox}!

  \bx{\usebox{\mybox}}

  \item[\bs{raisebox}\{dimension\}{[}height{]}{[}depth{]}\{contents\}] raises the contents by dimension. This is, the baseline of the box is moved downwards (or upwards if dimension is negative). The resulting box can have the given height and depth.\\ Example:
  \begin{verbatim}
    \bx{\raisebox{3pt}{Hello}}Hello
    \bx{\raisebox{-3pt}{Hello}}Hello
    \bx{\raisebox{3pt}[5pt][2pt]{Hello}}Hello
  \end{verbatim}

  \bx{\raisebox{3pt}{Hello}}Hello
  \bx{\raisebox{-3pt}{Hello}}Hello
  \bx{\raisebox{3pt}[5pt][2pt]{Hello}}Hello

  \item[\bs{rule}{[}raise{]}\{width\}\{thickness\}] Creates a box fully covered with ink. If width or thickness is zero it will not be visible in the document, but the box will occupy some space.\\ Example: \verb!\rule{1em}{1ex} \rule{10em}{0pt} \rule[5pt]{1em}{1ex}!

  \bx{\rule{1em}{1ex}} \bx{\rule{10em}{0pt}} \bx{\rule[5pt]{1em}{1ex}}

  Notice that the rule in the middle can be seen because of the \bs{bx} command. Otherwise it would be invisible.

  \item[\bs{llap}\{contents\}] Collapses the box of contents to a vertical line at the right. In math mode use \bs{mathllap} instead, which is provided by the {\ttfamily mathtools} package.

  \item[\bs{clap}\{contents\}] Collapses the box of contents to a vertical line at the center. In math mode use \bs{mathclap} instead. Both commands are provided by the {\ttfamily mathtools} package.

  \item[\bs{rlap}\{contents\}] Collapses the box of contents to a vertical line at the left. In math mode use \bs{mathrlap} instead, which is provided by the {\ttfamily mathtools} package.\\ Example:
  \begin{verbatim}
    \hfil
    \llap{\Huge a}
    \hfil
    \rlap{\Huge a}
    \hfil
    \clap{\Huge a}
    \hfil
  \end{verbatim}

    \hfil
    \bx{\llap{\Huge a}}
    \hfil
    \bx{\rlap{\Huge a}}
    \hfil
    \bx{\clap{\Huge a}}
    \hfil

 Notice the differences between these formulas. Can you guess what we did in the second one?

 $$ X = \sum_{1\leq i \leq j \leq n} X_{ij} \hspace{3cm} X = \sum_{\mathclap{1\leq i \leq j \leq n}} X_{ij}$$

  \item[\bs{smash}\{contents\}] Collapses the box of contents to a horizontal line at the bottom. Works in text mode and math mode.\\ Example: \verb!\smash{Hello}!

  \bx{\smash{Hello}}

  \item[\bs{phantom}\{contents\}] Creates a box with the dimensions of contents but without ink. Works in text mode and math mode.\\ Example: \verb!\phantom{Hello}!

  \bx{\phantom{Hello}}

\end{description}

\bibliographystyle{siam}
\bibliography{my_bibliography.bib}

\end{document}


\vsssub
\subsubsection{~Distributed memory concepts.} \label{sec:distr}
\vsssub

The general grid structure described in the previous paragraph is used for
both shared and distributed memory versions of the model, with some minor
differences. For the distributed memory version of the model, not all data is
kept at each processor. Instead, each spectrum is kept at a single processor
only. The spectra on the storage grid are distributed over the available
processors with a constant stride. Because only part of the spectra are stored
locally on a given processor, a distinction needs to be made between the above
global sea point counter {\F isea}, and the local sea point counter {\F
jsea}. If the actual number of processors used in the computation is {\F
naproc}, and if {\F iaproc} is the processor number ranging form 1 to {\F
naproc}, these parameters are related in the following way

\vspace{\baselineskip}
\centerline{\F isea = iaproc + (jsea-1) naproc ,}
\centerline{\F jsea = 1 + (isea-1) / naproc ,}
\centerline{\F iaproc = 1 + mod(isea-1,naproc) .}
\vspace{\baselineskip}

\noindent
In model version 3.10, a further refinement was introduced. The actual number
of processors {\F naproc} can be smaller than the total number of processors
used by the program ({\F ntproc}). Processors where {\F naproc} $<$ {\F
iaproc} $\le$ {\F ntproc} are reserved for output processing only.

With this data distribution, source terms and intra-spectral propagation can
be calculated at the each given processor without the need for communication
between processors. For spatial propagation, however, a data transpose is
required where the spectral components {\F(ith,ik)} for all spatial grid
points have to be gathered at a single processor. After propagation has been
performed, the modified data have to be scattered back to their `home'
processor. Individual spectral components are assigned to specific processors
in such a way that the number of partial propagation steps to be performed by
each processor is roughly identical. This makes a good load balance
possible. The actual algorithm can be found in section 4.d of the subroutine
{\F w3init} ({\file w3initmd.ftn}).

The data transpose for the gather operation is implemented in two steps using
the Message Passing Interface (MPI) standard \citep[e.g.][]{bk:GLS97}. First,
values for each spatial grid point for a given spectral bin {\F(ith,ik)} are
gathered in a single target processor in a one-dimensional array {\F
  store(isea)}, which then is converted to the full two-dimensional field of
spectral components. After propagation has been performed, the transpose for
the scatter operation reverses this process, using the same one-dimensional
array {\F store}. Whereas the algorithm for distributing spatial propagation
over individual processors assures a global (per time step) load balance, it
does not assure that communication is synchronized, because not each
calculation at each processor will take the same effort. To avoid that this
results in a load imbalance, non-blocking communication has been
used. Furthermore, the one-dimensional array {\F store(isea)} is replaced by
{\F store(isea,ibuf)}, where the added dimension of the array supplies an
actively managed buffer space (see {\F w3gath} and {\F w3scat} in {\file
  w3wavemd.ftn}). These buffers allow that spare clock cycles as may occur
during communication can be used for calculation, and that hiding of
communication behind calculation will occur if the hardware is capable of
doing this. To avoid problems with incompatibilities between FORTRAN and MPI,
separate gather and scatter data arrays are used.  The buffered data
transposes are graphically depicted in Fig.~\ref{fig:transpose}. More details
can be found in \cite{tol:PACO02}.

% fig:transpose

\input{sys/fig_transpose}

In principle only the storage array {\F a(ith,ik,jsea)} is influenced by the
data distribution. Input fields, maps and output fields of mean wave
parameters in principle are retained at full resolution at each grid
point. Full maps are available at each processor at each phase of the
calculation. Input and output fields generally contain pertinent data at the
stride {\F naproc} only.

Distributed memory also requires modifications to the I/O. Input files are
read completely by each separate processor. The type of file output is
determined by the I/O type indicator {\F iostyp}.

\begin{center} \begin{tabular}{cl}
{\F iostyp} & implies \\ \hline
  0 & Restart file written from each individual process. \\
  1 & Each file written from assigned process. \\
  2 & Each file written from a single dedicated output process. \\
  3 & Dedicated output processes for each output type.
\end{tabular} \end{center}

\noindent
Note that the restart file is a direct access file, so that each processor can
efficiently gather only the locally stored spectra, without the need of
reading through the entire file. The restart file is either written by each
individual process directly, or all data is funneled through a dedicated
processor. The first method requires a parallel file system, the second method
is generally applicable.

The present algorithm for data distribution has been chosen for several
reasons. First, it results in an automatic and efficient load balancing with
respect to the (dynamic) integration of source terms, the exclusion of ice
covered grid points, and of intra-spectral propagation. Secondly, the
communication by definition becomes independent of the numerical propagation
scheme, unlike for the more conventional domain decomposition. In the latter
case, only a so-called `halo' of boundary data needs to be converted to
neighboring `blocks' of grid points. The size of the halo depends on the
propagation scheme selected. The main disadvantage of the present data
distribution scheme is that the amount of data to be communicated each time
step is much larger than for a more conventional domain decomposition,
particularly when relatively small numbers of processors are used. On an IBM
RS6000 SP, on which the distributed memory version of \ws\ was tested, the
relatively large amount of communication did not constitute a significant part
of the overall time of computation, and the model shows excellent scaling
behavior for up to O(100) processors \citep{tol:PACO02}.

More recently, hybrid parallelization techniques have been developed using a
combination of a course scale domain decomposition and a local data transpose,
using approaches already available in {\file ww3\_multi}. To accommodate this,
the {file ww3\_gspl(.sh)} tools were introduced in model version
4.10. Although this approach still needs some work with respect to the model
memory footprint in the initialization in {\file ww3\_multi}, initial scaling
results obtained with this approach are encouraging \cite[see][]{tol:MMAB13b}.


\documentclass{beamer}
\usefonttheme[onlymath]{serif}
\usepackage[english]{babel}							%For internationalization
\usepackage[utf8]{inputenc}							%For character encoding
\usepackage{amsmath}								%For mathematical typesetting
\usepackage{amssymb}								%For mathematical typesetting
\usepackage{graphicx}								%For handling graphics
\usepackage{listings}

\newcommand{\be}{\begin{equation}}
\newcommand{\bea}{\begin{equation*}}
\newcommand{\ben}[1]{\begin{equation}\label{#1}}
\newcommand{\ee}{\end{equation}}
\newcommand{\eea}{\end{equation*}}
\newcommand{\aq}{\overset{\sim}{q}}

\title
{An Introduction to Discontinuous Galerkin Methods}
\subtitle{Module 3A: To Higher-Orders - Solution Approximation}
\author[Bevan] % (optional, for multiple authors)
{J.~Bevan}
\institute[UMass Lowell]
{
  Department of Mechanical Engineering, Grad Student\\
  University of Massachusetts at Lowell
}
\date[Fall 2014]
{}
\subject{Discontinuous Galerkin}

\begin{document}
\frame{\titlepage}
\frame{\frametitle{Module 3A: To Higher-Orders - Solution Approximation}\tableofcontents}

%NEW SECTION
\section{Weak Form- Revisited}
\subsection{Approximation Space}
\frame{\frametitle{\textbf{\secname}: \subsecname}
\be \int_{\Omega} \frac{\partial q}{\partial t} \phi_j \,dx + \int_{\Omega} \frac{\partial f(q)}{\partial x} \phi_j \,dx = 0 \ee
\begin{itemize}
\item Let's revisit the weak form in greater detail, we glossed over some important details.
\item To get a flexible method, we'd like to be able to generate an arbitrary order solution approximation. How do we do this in code?
\item We glossed over the construction of the bases, we can think in terms of nodal or modal
\be \aq(x) = \sum_{i=0}^M a_i \psi_i(x) \ee
\end{itemize}
}

\subsection{$L^2$ Projection: Minimize norm}
\frame{\frametitle{\subsecname}
\begin{itemize}
\item Where does the weak form come from? Approximate sol'n doesn't satisfy the PDE exactly, left with some residual
\be \frac{\partial \aq}{\partial t} \,dx + \frac{\partial f(\aq)}{\partial x}\,dx = R(x) \ee
\item A projection finds the "closest" fit on a vector space compared to the original. An orthogonal projection does just this.
\item Minimizes the $L^2$ norm wrt the space projected upon
\end{itemize}
}

\subsection{The Galerkin Condition}
\frame{\frametitle{\subsecname}
\begin{itemize}
\item An orthogonal projection means that the difference between the original and the projection should be orthogonal to the space projected upon, so for each basis $\phi \in V_h$
\be \int (f-f_h) \, \phi \,dx =0 = \int R(x) \phi \,dx\ee
\item The projected space doesn't have to be the same space as the solution approximation, but if we do choose them to be the same we have the Bubnov-Galerkin approach
\item We could choose the two spaces to be different, this is a Petrov-Galerkin approach. As an example, a weight space of delta functions yields a collocation method
\end{itemize}
}

%NEW SECTION
\section{Arbitrary Order Basis: Monomials?}
\frame{\frametitle{\textbf{\secname}}
\begin{itemize}
\item Let's continue with the choice of polynomials for our basis functions.
\item The easy and obvious choice is the monomials $\psi_i(x) = a_i x^i$ so the arbitrary order solution approximation is
\be \aq(x) = \sum_{i=0}^M a_i \psi_i(x)= \sum_{i=0}^M a_i x^i  \ee
\item Can you think of why this a poor choice for a vector basis? Remember a basis needs to be complete and linearly independent. Let's see two separate ways why this is a poor choice.
\end{itemize}
}

\subsection{Linear Dependence}
\frame{\frametitle{\subsecname}
\begin{itemize}
\item Normalize the basis wrt to the $L^2$ norm $\vert g \vert = \sqrt{\int g^2}$ so $\bar{\psi}_i=\sqrt{2i+1}x^i$
\item Consider the inner product of two adjacent basis functions
\be \int \bar{\psi}_{i-1} \bar{\psi}_{i} \,dx = \sqrt{1-\frac{1}{4i^2}} \ee
\item Linearly independent vectors are orthogonal, that is their inner product is zero. But for our monomials, even moderate values of $i$ give an inner product of close to 1
\item Very nearly dependent basis vectors mean small perturbations can lead to trouble finding the correct solution
\end{itemize}
}

\subsection{The ill-conditioned Hilbert matrix}
\frame{\frametitle{\subsecname}
\begin{itemize}
\item The alternate way to consider this is to look at the mass matrix for a monomial basis
\item $1$
\item $x$
\item $x^2$
\item $x^3$
\item When we integrate from 0 to 1 it is easy to see the pattern of values, this is a Hilbert matrix
\item It is ill-conditioned, let's see why this is a problem in Matlab
\end{itemize}
}

%NEW SECTION
\section{[Recall] Lagrange Interpolation}
\frame{\frametitle{\textbf{\secname}}
\begin{itemize}
\item Instead of a monomial basis, what if we were to use a Lagrange basis (commonly used for interpolation)
\item Recall, the Lagrange basis is zero at all interp nodes except the basis node, which it is 1 at
\item It has the form
\be L_q(x) = \prod_{p=1,p\neq q}^{Np} \frac{x-x_p}{x_q-x_p} \ee
\item We can compactly represent this as
\textit{nn=elim(nd(1:N)',nd(1:N)',[1 3 2]);\\
Lag= @(x,nv) prod(bsxfun(@rdivide,bsxfun(@minus,x,nn(nv,:,:)),...\\
bsxfun(@minus,nd(nv),nn(nv,:,:))),3)}
\end{itemize}
}

%NEW SECTION
\section{Lagrange Spatial Approximation}
\frame{\frametitle{\textbf{\secname}}
\begin{itemize}
\item We can now represent our arbitrary order sol'n approximation
\be \aq(x) = \sum_{i=0}^M a_i \psi_i(x)= \sum_{i=0}^M q(x_i) L_i(x)  \ee
\item Where we must choose a collection of points to use as our interpolation nodes
\end{itemize}
}

%NEW SECTION
\section{Interpolation Points: Equispaced?}
\frame{\frametitle{\textbf{\secname}}
\begin{itemize}
\item It would seem logical that equispaced points are a good choice. They evenly cover the domain and are simple to calculate positions for.
\item Indeed these points work well for low $Np$, so one would expect the accuracy to increase as $Np$ increases
\item Let's see how it behaves at large $Np$
\end{itemize}
}

%NEW SECTION
\section{Runge's Phenomenon}
\frame{\frametitle{\textbf{\secname}}
\begin{itemize}
\item The divergence of the interpolation is a result of Runge's phenomenon
\item Why this fails is explainable in terms of two relations: the Bernstein and Markov Inequalities. For a polynomial $P^N \in [-1, 1]$
\be |P^{\prime}(x)| \leq \frac{N}{\sqrt{1-x^2}}\| P \| _{\infty} \ee
\item The singularity in the Bernstein inequality can be bounded by the Markov inequality
\be \| P^{\prime} \| {\infty} \leq N^2 \| P \|_ {\infty} \ee
\item With the overall being
\be |P^{\prime}(x)| \leq \min \left(\frac{N}{\sqrt{1-x^2}},N^2\right)\| P \|_ {\infty} \ee

\end{itemize}
}

%NEW SECTION
\section{Interpolation Points: Legendre Roots}
\frame{\frametitle{\textbf{\secname}}
\begin{itemize}
\item The overall inequality implies we'd like quadratic spacing near the element boundaries.
\item Though it may seem arbitrary, the roots of the Legendre polynomials have a favorable spacing that matches out needs
\item They avoid Runge's phenomenon, and have several other very nice features we shall see in the next module
\begin{figure}
\centering
\includegraphics[width=2in]{LegPolys.PNG}
\end{figure}
\centering
\tiny http://en.wikipedia.org/wiki/File:Legendrepolynomials6.svg
\end{itemize}
}

\end{document}


\section{Templates}
\label{sec:templates}

\begin{multicols}{2}
%
% New Spacecraft
%
  \subsection{New Spacecraft}
  \label{sec:template-spacecraft}

  \subsubsection{Fighters}
  \label{sec:template-fighters}

  \textbf{Osa T-1}
  \begin{standardtable}{\linewidth}{sb}
    \textbf{Make}       & Sakeena Shipyards\\
    \textbf{Hull}       & Fighter\\ % Base Cost = 100k
    \textbf{Rank}       & Novice\\
    \textbf{Wounds}     & 1\\
    \textbf{Armour}     & d4\\ % 50k
    \textbf{Engines}    & d4\\ % 50k
    \textbf{Power}      & d8\\ % 150k
    \textbf{Bulk}       & d6\\ % 100k
    \textbf{Systems}    & d8\\ % 200k
    \textbf{Skills}     & ECM d8; Navigation d6; Sensors d6; Weapons d8\\
    \textbf{Crew}       & 1\\ % Base = 1
    \textbf{Storage}    & 5\\ % Base = 3 + 1.5
    \textbf{Power}      & 7\\ % Base = 5 + 1.5
    \textbf{Size}       & -1\\
    \textbf{Acc / TS}   & 50 / 700\\ % Base = 50/700
    \textbf{Evade}      & 2\\
    \textbf{Toughness}  & 3\\
    \textbf{Value}      & 550K\\
    \textbf{Maintenance} & 2.75K\\
  \end{standardtable}

  \textbf{Kestrel}
  \begin{standardtable}{\linewidth}{sb}
    \textbf{Make}       & Solar Spacecraft\\
    \textbf{Hull}       & Fighter\\ % Base Cost = 100k
    \textbf{Rank}       & Novice\\
    \textbf{Wounds}     & 1\\
    \textbf{Armour}     & d8\\ % Base = 150k
    \textbf{Engines}    & d6\\ % Base = 100k
    \textbf{Power}      & d4\\ % Base = 50k
    \textbf{Bulk}       & d4\\ % Base = 50k
    \textbf{Systems}    & d6\\ % Base = 150k
    \textbf{Skills}     & ECM d8; Navigation d6; Weapons d8\\
    \textbf{Crew}       & 1\\ % Base = 1
    \textbf{Storage}    & 3\\ % Base = 3
    \textbf{Power}      & 3\\ % Base = 5 - 2.5
    \textbf{Size}       & -1\\
    \textbf{Acc / TS}   & 50 / 700\\ % Base = 50/700
    \textbf{Evade}      & 2\\
    \textbf{Toughness}  & 5\\
    \textbf{Value}      & 500K\\
    \textbf{Maintenance} & 2.5K\\
  \end{standardtable}

  \textbf{Shaytan}
  \begin{standardtable}{\linewidth}{sb}
    \textbf{Make}       & Starlette Industries\\
    \textbf{Hull}       & Fighter\\ % Base Cost = 100k
    \textbf{Rank}       & Seasoned\\
    \textbf{Wounds}     & 1\\
    \textbf{Armour}     & d10\\ % Base = 200k
    \textbf{Engines}    & d6\\ % Base = 100k
    \textbf{Power}      & d6\\ % Base = 100k
    \textbf{Bulk}       & d4\\ % Base = 50k
    \textbf{Systems}    & d8\\ % Base = 200k
    \textbf{Skills}     & ECM d8; Navigation d8; Sensors d8; Weapons d8\\
    \textbf{Crew}       & 1\\ % Base = 1
    \textbf{Storage}    & 3\\ % Base = 3
    \textbf{Power}      & 5\\ % Base = 5
    \textbf{Size}       & -1\\
    \textbf{Acc / TS}   & 50 / 700\\ % Base = 50/700
    \textbf{Evade}      & 2\\
    \textbf{Toughness}  & 6\\
    \textbf{Value}      & 650K\\
    \textbf{Maintenance} & 3.25K\\
  \end{standardtable}

  \subsubsection{Shuttles}
  \label{sec:templates-shuttles}

  \textbf{Shangren Yi}
  \begin{standardtable}{\linewidth}{sb}
    \textbf{Make}       & Starlette Industries\\
    \textbf{Hull}       & Shuttle\\ % Base = 250K
    \textbf{Rank}       & Novice\\
    \textbf{Wounds}     & 2\\
    \textbf{Armour}     & d4\\ % 125k
    \textbf{Engines}    & d6\\ % 250k
    \textbf{Power}      & d6\\ % 250k
    \textbf{Bulk}       & d8\\ % 375k
    \textbf{Systems}    & d6\\ % 375k
    \textbf{Skills}     & Auto-pilot d6; Navigation d6; Operations d6; Repair d6; Sensors d6 \\
    \textbf{Crew}       & 4\\ % Base = 4
    \textbf{Storage}    & 20\\ % Base = 10
    \textbf{Power}      & 5\\ % Base = 5
    \textbf{Size}       & 0\\
    \textbf{Acc / TS}   & 40 / 600\\ % Base = 40 / 600
    \textbf{Evade}      & 5\\
    \textbf{Toughness}  & 4\\
    \textbf{Value}      & 1.375M\\
    \textbf{Maintenance} & 6.88K\\
  \end{standardtable}

  \subsubsection{Patrol}
  \label{sec:templates-patrol}

  \textbf{Kibo FFS}
  \begin{standardtable}{\linewidth}{sb}
    \textbf{Make}       & Sakeena Shipyards\\
    \textbf{Hull}       & Patrol\\ % Base = 250K
    \textbf{Rank}       & Novice\\
    \textbf{Wounds}     & 2\\
    \textbf{Armour}     & d4\\ % 125k
    \textbf{Engines}    & d8\\ % 375k
    \textbf{Power}      & d6\\ % 250k
    \textbf{Bulk}       & d8\\ % 375k
    \textbf{Systems}    & d4\\ % 250k
    \textbf{Skills}     & Auto-pilot d6; Navigation d6; Operations d4; Sensors d6\\
    \textbf{Crew}       & 4\\ % Base = 4
    \textbf{Storage}    & 10\\ % Base = 5
    \textbf{Power}      & 10\\ % Base = 10
    \textbf{Size}       & 0\\
    \textbf{Acc / TS}   & 45 / 600\\ % Base = 45/600
    \textbf{Evade}      & 5\\
    \textbf{Toughness}  & 4\\
    \textbf{Value}      & 1.375M\\
    \textbf{Maintenance} & 6.88K\\
  \end{standardtable}

  \subsubsection{Corvette}
  \label{sec:templates-corvette}

  \textbf{Falcon}
  \begin{standardtable}{\linewidth}{sb}
    \textbf{Make}       & Solar Spacecraft\\
    \textbf{Hull}       & Corvette\\
    \textbf{Rank}       & Novice\\ % Base = 500k
    \textbf{Wounds}     & 3\\
    \textbf{Armour}     & d6\\ % 500k
    \textbf{Engines}    & d8\\ % 750k
    \textbf{Power}      & d6\\ % 500k
    \textbf{Bulk}       & d4\\ % 250k
    \textbf{Systems}    & d6\\ % 750k
    \textbf{Skills}     & Navigation d6; Operations d6; Sensors d8; Weapons d6\\
    \textbf{Crew}       & 10\\ % Base = 10
    \textbf{Storage}    & 20\\ % Base = 20
    \textbf{Power}      & 15\\ % Base = 15
    \textbf{Size}       & +1\\
    \textbf{Acc / TS}   & 35 / 400\\ % Base = 35/400
    \textbf{Evade}      & 2\\
    \textbf{Toughness}  & 6\\
    \textbf{Value}      & 2.75M\\
    \textbf{Maintenance} & 13.75K\\
  \end{standardtable}

  \textbf{Hawk}
  \begin{standardtable}{\linewidth}{sb}
    \textbf{Make}       & Solar Spacecraft\\
    \textbf{Hull}       & Corvette\\
    \textbf{Rank}       & Seasoned\\ % Base = 500k
    \textbf{Wounds}     & 3\\
    \textbf{Armour}     & d6\\ % 500k
    \textbf{Engines}    & d10\\ % 1M
    \textbf{Power}      & d6\\ % 500k
    \textbf{Bulk}       & d8\\ % 750k
    \textbf{Systems}    & d8\\ % 1M
    \textbf{Skills}     & Auto-pilot d6; Navigation d8; Operations d4; Sensors d6; Weapons d6\\
    \textbf{Crew}       & 10\\ % Base = 10
    \textbf{Storage}    & 40\\ % Base = 20
    \textbf{Power}      & 15\\ % Base = 15
    \textbf{Size}       & +1\\
    \textbf{Acc / TS}   & 53 / 600\\ % Base = 35/400
    \textbf{Evade}      & 5\\
    \textbf{Toughness}  & 6\\
    \textbf{Value}      & 3.75M\\
    \textbf{Maintenance} & 18.75K\\
  \end{standardtable}
%
% Characters
%
  \subsection{New Characters}
  \label{sec:templates-characters}

  \subsubsection{Ghoa}
  \label{sec:templates-ghoa}

  \textbf{Ghoan Warrior}
  \begin{standardtable}{\linewidth}{sb}
    \textbf{Rank}       & Novice\\
    \textbf{Strength}   & d8\\
    \textbf{Agility}    & d8\\
    \textbf{Smarts}     & d4\\
    \textbf{Spirit}     & d4\\
    \textbf{Vigor}      & d8\\
    \textbf{Skills}     & Fighting d10; Shooting d10; Intimidation d8\\
    \textbf{Charisma}   & -4\\
    \textbf{Pace}       & 6\\
    \textbf{Parry}      & 7\\
    \textbf{Toughness}  & 6\\
    \textbf{Bloodthirsty} & -2 Charisma (included)\\
    \textbf{Natural Weapons} & Claws, Teeth and Tail does STR+d6\\
    \textbf{Reptile Blood} & -4 to resist cold\\
    \textbf{Stronger} & Start with a d6 in STR (included)\\
    \textbf{Free Edge} & Start with one free Novice Edge\\
  \end{standardtable}

  \subsubsection{Uplifted}
  \label{sec:templates-uplifted}

  \textbf{Bear Pirate}
  \begin{standardtable}{\linewidth}{sb}
    \textbf{Rank}       & Novice\\
    \textbf{Strength}   & d6\\
    \textbf{Agility}    & d8\\
    \textbf{Smarts}     & d4\\
    \textbf{Spirit}     & d4\\
    \textbf{Vigor}      & d8\\
    \textbf{Skills}     & Fighting d10; Shooting d10; Intimidation d8\\
    \textbf{Charisma}   & -4\\
    \textbf{Pace}       & 5\\
    \textbf{Parry}      & 7\\
    \textbf{Toughness}  & 9\\
    \textbf{Inferior} & -2 Charisma (included) \\
    \textbf{Primal Weapons} & Claws / Teeth does STR+d6 damage\\
    \textbf{Primitive Intellect} & -1 to Smarts-based checks\\
    \textbf{Bear Ancestry} & +1 Size, +3 Toughness (included)\\
    \textbf{Free Edge} & Start with one free Novice Edge\\
  \end{standardtable}

  \textbf{Ferret Infiltrator}
  \begin{standardtable}{\linewidth}{sb}
    \textbf{Rank}       & Novice\\
    \textbf{Strength}   & d4\\
    \textbf{Agility}    & d8\\
    \textbf{Smarts}     & d6\\
    \textbf{Spirit}     & d6\\
    \textbf{Vigor}      & d6\\
    \textbf{Skills}     & Shooting d8; Stealth d8; Survival d8\\
    \textbf{Charisma}   & -3\\
    \textbf{Pace}       & 8\\
    \textbf{Parry}      & 2\\
    \textbf{Toughness}  & 5\\
    \textbf{Inferior} & -2 Charisma (included) \\
    \textbf{Primal Weapons} & Claws / Teeth does STR+d6 damage\\
    \textbf{Primitive Intellect} & -1 to Smarts-based checks\\
    \textbf{Rodent Ancestry} & +4 Pace (included)\\
    \textbf{Free Edge} & Start with one free Novice Edge\\
  \end{standardtable}

  \textbf{Rabbit Cyberware Trader}
  \begin{standardtable}{\linewidth}{sb}
    \textbf{Rank}       & Novice\\
    \textbf{Strength}   & d4\\
    \textbf{Agility}    & d4\\
    \textbf{Smarts}     & d8\\
    \textbf{Spirit}     & d10\\
    \textbf{Vigor}      & d4\\
    \textbf{Skills}     & Computers d8; Persuasion d10; Repair d8\\
    \textbf{Charisma}   & -1\\
    \textbf{Pace}       & 8\\
    \textbf{Parry}      & 2\\
    \textbf{Toughness}  & 4\\
    \textbf{Inferior} & -2 Charisma (included) \\
    \textbf{Primal Weapons} & Claws / Teeth does STR+d6 damage\\
    \textbf{Primitive Intellect} & -1 to Smarts-based checks\\
    \textbf{Rodent Ancestry} & +4 Pace (included)\\
    \textbf{Free Edge} & Start with one free Novice Edge\\
  \end{standardtable}

\end{multicols}


% 20201005
\documentclass[env.tex]{subfiles}

\newcommand{\aq}{aquatic}
\newcommand{\te}{terrestrial}
\newcommand{\mL}{mixed layer}
\newcommand{\hg}{homogeneous}
\newcommand{\thl}{theoretical}
\newcommand{\sP}{subarctic Pacific}
\newcommand{\sgs}{Sargasso Sea}
\newcommand{\nA}{N. Atlantic}
\newcommand{\ds}{density}
\newcommand{\pl}{population size}
\newcommand{\mC}{molar Concentration}
\newcommand{\ct}{continuous}
\newcommand{\y}{yes}
\newcommand{\n}{no}
\newcommand{\ft}{fluctuation}
\newcommand{\sd}{steady}

\begin{document}
\subsection{Features comparison between models}

\begin{table}[H]
    \centering
    \caption[Model features comparison]{Table of features comparison (16 features) between model in this project with aquatic slab models (22 models) and two terrestrial nutrient cycle models}
    \label{modComp}
\end{table}

\begin{landscape}
\begin{longtable}{p{2cm}|p{.05\linewidth}p{.07\linewidth}p{.1\linewidth}p{.1\linewidth}p{.13\linewidth}p{.06\linewidth}p{.14\linewidth}p{.1\linewidth}}\hline
    model & year & system & structure & condition & location & element & unit & time-frame \\\hline
    this study & 2020 & \aq & CPB & \mL & \thl & C & \ds & \ct \\
    \parencite{evans1985model} & 1985 & \aq & NPZ & \mL & \sP & n.a. & \pl & spring \\
    \parencite{frost1987grazing} & 1987 & \aq & NP(Z) & \mL & \sP & n.a. & \pl & \ct \\
    \parencite{fasham1990nitrogen} & 1990 & \aq & 2NPZDB(DOM) & \hg & \sgs & N & \mC & \ct \\
    \parencite{robinson1993simulated} & 1993 & \aq & P2Z & \mL & upwell Pacific & C & \ds & by-year \\
    \parencite{fasham1995use} & 1995 & \aq & 2NPZDB(DOM) & - & \sP & - & - \\
    \parencite{matear1995parameter} & 1995 & \aq & 2NP2ZDB(DOM) & \mL & \sP & n.a. & \pl & \ct \\
    \parencite{hurtt1996pelagic} & 1996 & \aq & 2NPR & \mL & \sgs & N & \mC & \ct \\
    \parencite{xiao1996relative} & 1996 & \te & CNP & dual cycles & \thl & C, N & \ds & \ct \\
    \parencite{popova1997chaotic} & 1997 & \aq & NPZD & \mL & \thl & N & \mC & \ct \\
    \parencite{anderson1998modelling} & 1998 & \aq & 2NPZDB(DOM) & slab & Engligh Channel & N & \mC & \ct \\
    \parencite{spitz1998data} & 1998 & \aq & 2NPZDB(DOM) & \mL & \sgs & N & \mC & \ct \\
    \parencite{fennel2001testing} & 2001 & \aq & NPZD & \mL & \sgs & N & \mC & \ct \\
    \parencite{natvik2001weak} & 2001 & \aq & NPZ & - & Flemish Cap & - & - & - \\
    \parencite{schartau2001parameter} & 2001 & \aq & NPZ & \mL & \sgs & N & \mC & \ct \\
    \parencite{spitz2001configuring} & 2001 & \aq & 2NPZDB(DOM) & \mL & \sgs & N & \mC & \ct \\
    \parencite{ito2002simulation} & 2002 & \te & CP & \hg & \thl & C & \ds & no \\
    \parencite{hemmings2004split} & 2004 & \aq & NPZ & - & \nA & - & - & - \\
    \parencite{onitsuka2005differences} & 2005 & \aq & NPZD, 2N2P3Z(DOM) & slab & Japan sea & N & \mC & \ct \\
    \parencite{findlay2006modelling} & 2006 & \aq & NP & \mL & \thl & hypo & \mC & \ct \\
    \parencite{mitra2007accounting} & 2007 & \aq & 2NPZDB(DOM) & \hg & \nA & N & \mC & short \\
    \parencite{mitra2009closure} & 2009 & \aq & 2NPZDB(DOM) & \hg & \nA & N & \mC & \ct \\
    \parencite{llebot2010role} & 2010 & \aq & 2N2PD(DOM) & \hg & Mediterranean Bay & N & \mC & \ct \\
    \parencite{kidston2013phytoplankton} & 2013 & \aq & NPZD & \mL & Southern Ocean & N & \mC & \ct \\
    \parencite{anderson2015empower} & 2015 & \aq & NPZD & \mL & \thl & N & \mC & \ct \\
\hline\end{longtable}

\begin{longtable}{p{2cm}|p{.07\linewidth}p{.1\linewidth}p{.1\linewidth}p{.1\linewidth}p{.1\linewidth}p{.1\linewidth}p{.1\linewidth}p{.1\linewidth}}\hline
    model & thermocline & density-depend motality & trophic levels (main level + decomposer) & explicit players & sunlight & system setting & respiration & resource allocation \\\hline
    this study & \n & \phy & 1+1 & \y & \n & \ft & \y & \y \\
    \parencite{evans1985model} & \y & \n & 1+0 & \y & \y & \sd & \n & \n \\
    \parencite{frost1987grazing} & \y & \n & 2+0 & \n & \y & \sd & \n & \n \\
    \parencite{fasham1990nitrogen} & \y & \n & 2+1 & \y & \n & \sd & \n & \n \\
    \parencite{robinson1993simulated} & \y & unknown & 3+0 & no equations & \y & \ft & \n & \n \\
    \parencite{fasham1995use} & - & - & - & model 03 & - & - & \n & \n \\
    \parencite{matear1995parameter} & \y & \n & 2+0 & \y & \y & \ft & \n & \n \\
    \parencite{hurtt1996pelagic} & \y & \n & 1+0 & model 03 & \n & \sd & \n & \n \\
    \parencite{xiao1996relative} & \n & \n & 1+1 & \y & \y & \sd & \y & \y \\
    \parencite{popova1997chaotic} & \y & \n & 2+0 & \y & \y & \ft & \n & \n \\
    \parencite{anderson1998modelling} & \y & \n & 2+1 & \n & \y & \ft & \n & \n \\
    \parencite{spitz1998data} & \y & \n & 2+1 & \y & \y & \ft & \n & \n \\
    \parencite{fennel2001testing} & \y & \n & 2+0 & \y & \y & \ft & \n & \n \\
    \parencite{natvik2001weak} & - & - & - & no equations & - & - & \n & \n \\
    \parencite{schartau2001parameter} & \y & \n & 2+0 & \n & \y & \ft & \n & \n \\
    \parencite{spitz2001configuring} & \y & \n & 2+1 & model 11 & \n & \ft & \n & \n \\
    \parencite{ito2002simulation} & \n & \n & 1+0 & \y & \n & \sd & \n & \n \\
    \parencite{hemmings2004split} & - & - & - & statistical & - & - & \n & \n \\
    \parencite{onitsuka2005differences} & \y & \n & 2+0 & \y & \n & \ft & \n & \n \\
    \parencite{findlay2006modelling} & \y & \n & 1+0 & \n & \n & \ft & \n & \n \\
    \parencite{mitra2007accounting} & \n & \n & 2+1 & \n & \n & perturbation & \n & \n \\
    \parencite{mitra2009closure} & \n & \n & 2+1 & \y & \n & cannibalism & \n & \n \\
    \parencite{llebot2010role} & \n & \n & 2+0 & \y & \y & \sd & \n & \n \\
    \parencite{kidston2013phytoplankton} & \y & \phy & 2+0 & \y & \y & \sd & \n & \n \\
    \parencite{anderson2015empower} & \y & \phy & 2+1 & \y & \y & \ft & \n & \n \\
\hline\end{longtable}
\end{landscape}

\end{document}


\section{Basic Analysis}
\label{891_2:sec:anal}

To quantify uncertainties in our full spectrum galaxy fits we will
test different methods of fitting spectra and interpreting the
results. In this section we describe the basic, high-level methodology
that is common to all fitting methods. We also detail preparatory
analysis that is required before these methods can be applied to our
data, namely determining the velocity of each aperture and correcting
for Balmer emission.

%+++++++++++++++++++++++++++
%% {\bf MAB: Itemize (not in bullets, in sentences, clauses) the detailed
%%   preparatory analysis you will be describing. ``running the data
%%   through full spectrum fitting'' should be re-worded.

%------------------------
%% You should also have some preliminary discussion about why you are
%% laying the basics on the ``SSP fitting methodology.'' (I would call it
%% SPS not SSP, i.e., your SPS involves adding together SSPs.) For
%% example, there are the issues of degeneracies between age, metallicity
%% and extinction. There is also the issue of assumptions about the SFH
%% on $\tau_L$ and $Z_L$ for which the data cannot offer resolution,
%% i.e., the data does not allow you to know about the detailed SFH for
%% the older stellar populations. In other words, what is going to lead
%% you ultimately to the DFK approach. Foreshadow this.}

\subsection{SSP fitting methodology}
\label{891_2:sec:SSP_method}

Our fitting method involves minimizing differences between measured
NGC 891 spectra and synthetic galaxy spectra constructed from the
superposition of simple stellar populations (SSPs, see
\S\ref{891_2:sec:SSP_sets}). Fits are performed with
MPFITFUN\footnote{available at \url{http://purl.com/net/mpfit}}
\citep{Markwardt09}, an IDL implementation of the MINPACK Levenberg
Marquardt minimization algorithm \citep{More78}. The model galaxy
spectra are defined as
\begin{equation}
\label{891_2:eq:SSP_galaxy}
g(\lambda) = R(\lambda,\tau_V) \sum_{i,j} M(\Delta t_i,Z_j)
f(\lambda,\Delta t_i, Z_j),
\end{equation}
where $f(\lambda, \Delta t_i, Z_j)$ is the spectrum of an SSP with
metallicity $Z_j$ formed over time interval $\Delta t_i$, $M(\Delta
t_i,Z_j)$ quantifies the strength of the contribution of each SSP, and
$R(\lambda, \tau_V)$ governs the total extinction in the galaxy. All of our
SSPs are normalized to \val{1}{\sol{M}} so the strength of each SSP is
simply
\begin{equation}
\label{891_2:eq:fit_weight}
M(\Delta t_i,Z_j) = \int_{\Delta t_i} \psi(t, Z_j) dt,
\end{equation}
where $\psi(t, Z_j)$ describes the mass of stars formed at time $t$
with metallicity $Z_j$ (i.e., the star formation rate). In other
words, $M(\Delta t_i,Z_j)$ is the total mass in stars formed during
the time interval, $\Delta t_i$, associated with a particular SSP. The
extinction, $R(\lambda, \tau_V)$, is parametrized by a single
variable, $\tau_V$ and, importantly, does not depend on SSP age
($t_i$) or metallicity ($Z_j$). In \S\ref{891_2:sec:extinction} we
discuss the details of $R(\lambda, \tau_V)$ and the limitations of
this simplification. During fitting the free parameters are the SSP
weights ($M(\Delta t_i,Z_j)$) a single extinction term (\tauV), and the
systematic velocity.

%+++++++++++++++++++++++++++++
%% {\bf MAB: You should reference Levenberg Marquardt but I do not think
%%   you need to describe your coding language or the implementation in
%%   MPFITFUN. Concerning equation (1), you need to mention here what is
%%   being assumed given the placement of R. You can discuss it more
%%   later (in 3.3), but you should at least note the implications here
%%   and point to that later discussion here.}

For each aperture our primary values of interest are the age,
metallicity, and extinction. We measure extinction directly as $A_V =
1.086\ \tauV$, but age and metallicity depend on assumptions made
during fitting (i.e., priors in the SSP library) and during subsequent
analysis.

As shown in Equation \ref{891_2:eq:fit_weight} the fit weights describe the
integral of a particular star formation history (SFH), but it is
useful to reduce a SFH down to single values for age and
metallicity. To do this we define a pair of light-weighted
quantities. The mean, light-weighted age is
\begin{equation}
\label{891_2:eq:MLWA}
\tau_L = \frac{\sum_{i,j} W_{L,i,j}\times t_i}{\sum_{i,j} W_{L,i,j}}
\end{equation}
where $t_i$ is the age associated with each SSP and $W_L$ is the
``light weight'', defined as
\begin{equation}
\label{891_2:eq:light_weight}
W_{L,i,j} = M(\Delta t_i,Z_j)\sum_k S(\lambda_k) R(\lambda_k, \tau_V)
f(\lambda_k, \Delta t_i, Z_j),
\end{equation}
where $S(\lambda_k)$ defines a bandpass over which the light weight is
computed. We set $S(\lambda_k)$ to be flat over \val{5450}{\AA}
$\leq\lambda\leq$ \val{5550}{\AA} and zero everywhere else. The choice
of $t_i$ depends on assumptions about the SFH and in this work we make
the simple assumption that star formation is constant across the
lifetime of each SSP ($\Delta t_i$) so that $t_i$ is simply the
midpoint of each $\Delta t_i$. In \S\ref{891_2:sec:sys_err} we discuss
and quantify the systematics that arise from such an assumption. We
note that Equation \ref{891_2:eq:light_weight} also describes a
conversion from mass-weights (i.e., $M(\Delta t_i, Z_j)$) to
light-weights that is simply a constant that is independent of the
specific mix of SSPs (but does depend on the overall extinction).

Similarly to $\tau_L$ we also define the mean, light-weighted
metallicity as
\begin{equation}
\label{891_2:eq:MLWZ}
Z_L = \frac{\sum_{i,j} W_{L,i,j}\times Z_j}{\sum_{i,j} W_{L,i,j}}.
\end{equation}

%+++++++++++++++++++++++
%% {\bf MAB: In eqn (4) move M outside of the sum since it does not
%%   depend on wavelength to clearly indicate that the factor between the
%%   light weight and the mass (weight) is a contant factor that depends
%%   on age and metallicity for a given band-pass. And say as much.}

\subsection{Velocities}
\label{891_2:sec:vel}

The systemic velocities of our model galaxies do not depend on the
shape of the spectra (i.e., the SSP mix) and thus we can reduce the
number of free parameters in our SSP fits by measuring the velocities
once and then keeping them fixed for all subsequent analysis. The
velocity values we use are a combination of velocity estimates from
two sources: the ``fit'' velocities that result from SSP fitting, and
velocities measured from the centers of bright emission lines.

%++++++++++++++++++++++
%% {\bf MAB: Do you mean ``systematic velocities'' or do you mean
%%   ``systemic velocities'' or ``line of sight velocities'' ? At the end
%%   of the paragraph enumerate in words what the following two
%%   subsubsections are.}

\subsubsection{Fit velocities}
During full spectrum fitting the velocity can be a free parameter of
the model, and this fit provides the first estimate of the velocity of
each aperture. The first step is to run a fully unconstrained fit
where all SSP weights, the velocity, and the extinction are allowed to
vary (see \S\ref{891_2:sec:SSP_method}). This produces a ``best fit''
only in the sense that the resulting model spectrum matches the data
well in a $\chi^2$ sense; to determine velocities the details of the
astrophysical assumptions behind each model are unimportant. The
reported fit uncertainties on these velocities is on the order of
\val{\asim10}{\kms}, depending on \GP fiber size (see Chapter
\ref{chap:891_1}), which is slightly better that 10\% of the
instrumental resolution (again, depending on fiber size).

%++++++++++++++++++
%% {\bf MAB: Discuss the centroiding accuracy in terms of the
%%   instrumental resolution.}

Once the ``best fit'' spectrum is determined we run a second iteration
of the fitting routine with the SSP weights and extinction fixed to
the best fit values. This keeps the shape of the model spectrum the
same and causes $\chi^2$ minimization to be driven only by the
velocity offset between the model and the data. When fitting these
velocities we used only the range of wavelengths that lie within the
region spanned by arc lamp lines ($\val{4100}{\AA} \leq\lambda\leq
\val{6600}{\AA}$). This avoids wavelengths that could be affected by
extrapolation of the wavelength solution (see Chapter
\ref{chap:891_1}). In the majority of apertures this ``refined''
velocity was within \val{\asim 10}{\kms} of the original fit velocity,
which is similar to the precision of the fits and indicates that this
second iteration is perhaps not necessary.

%+++++++++++++++=
%% {\bf MAB: How important is this iteration? Again, compare amplitude of
%%   the change in the iteration to the instrumental resolution.
%% Refer to Paper-I concerning the wavelengths spanned by arcs (at the end of
%% the last sentence of the par.
%% }

The results of these fits produce what we call the ``fit
velocities''. The final fit values were found to be stable to a wide
(\val{\asim 100}{\kms}) range of starting velocity values. These
velocity fits are driven mainly by regions of the spectrum that
deviate significantly from the continuum level, which in our case are
the Balmer absorption series, the MgI absorption band, and the G
band. Many apertures show moderate to strong \Ha emission, but we
masked this feature (and [OIII]) during fits because our model SSPs do
not have nebular emission. For this reason the $\chi^2$ velocities can
be though of as the ``stellar'' velocity values.

%% {\bf MAB: Do you mask the upper Balmer series, including H-beta? I
%%   would have thought this would be important, and I thought you did.}

%% Comment for MAB: we actually didn't mask \HB. In retrospect maybe we
%% should have, but it is a rare aperture indeed that has strong enough
%% \HB emission to really mess with the residuals. Besides, the other
%% strong absorption features are certainly enough to simply fit a
%% centroid.

\begin{figure*}[t]
  \centering
  \includegraphics[width=\textwidth]{891_2/figs/Swat_vel.pdf}
  \caption[Comparison of measure stellar and gas velocities to HI
    velocity data]{\fixspacing\label{891_2:fig:Swat_vel}Comparison of
    HI velocity envelope (from \citet{Swaters97}) to \emph{left:}
    measured H$\alpha$ centroids, \emph{middle:} best fit velocities
    from SSP models, and \emph{right:} best fit stellar velocities
    with a constant offset to minimize median difference between gas
    and stars.}
\end{figure*}

\subsubsection{Emission line velocities}

As a check on the velocities found above we also measure the velocity
of nebular emission lines, namely \Ha. Centroids were computed using
the IRAF task FITPROFS which allows us to deblend the \Ha, [NII]
complex. We focus only on the \Ha velocities, which are then compared
to known HI velocities from \citet{Swaters97}, as shown in the left
panel of Figure \ref{891_2:fig:Swat_vel}. We call the velocities measured in
\Ha ``gas velocities''.

%+++++++++++++++=
%% {\bf MAB: While I am ok with us comparing to Swaters+97 in Figure 1,
%%   are you taking into account in all of this analysis the trend in the
%%   HI tangential speed with height found in Oosterloo+07? This is
%%   essential I think. Last sentence are you measuring \Ha velocities or
%%   \Ha+[NII] velocities?}

The center panel of Figure \ref{891_2:fig:Swat_vel} shows the
``stellar velocities'' compared to known HI velocities and our
measured \Ha velocities. Clearly there is a systematic offset between
the stellar and gas velocities and we find that this offset is
constant in magnitude and sign across both sides of the galaxy. This
fact rules out an offset caused by asymmetric drift
\citep{Binney87}. Furthermore, many of the stellar velocities are
unphysical in the sense that they lie outside of the HI envelope. We
therefore conclude that this offset is caused by systematic
measurement uncertainty (likely arising from uncertainty in our
wavelength solution) and compute a constant velocity ``correction''
that is applied to the stellar velocities. This offset is computed to
minimize the median difference between stellar and gas
velocities. While we do expect the stellar tangential speed to lag
behind the gas the fact that we measure both sides of the galaxy
means, the median difference between gas and stars should be, to first
order, zero.

%+++++++++++++++++++++
%% {\bf MAB: I made a few edits in the above par. As part of or before
%%   the sentence beginning ``Clearly, ...'', add a description of what
%%   you see in Figure 1 that is clearly unphysical, i.e., the negative
%%   velocities in the middle panel below the gas. More broadly, discuss
%%   first the distribubtion of the ionized gas velocity w.r.t. the
%%   envelop from HI. This envelop should be noted in the text and the
%%   figure caption. Explain why we might expect the ionized gas to lie
%%   below the HI envelop, i.e., we are measuring a centroid. What should
%%   the reader make of the few points in the upper part of the left
%%   panel that are above the HI envelope? Are these bad measuremets? Add
%%   error bars?

%%   Define AD -- you can reference Binney \& Tremaine.

%%   Discuss what the soures of possible uncertainty could be in the
%%   stellar velocities. Is this a problem with the wavelength solution
%%   -- something that you come to in the next paragraph, or something
%%   else? Did you check that the wavelength solution and the BC03
%%   templates were either both in vacuum or air?

%---------------------
%%   Lastly, concerning the use of the median, yes, maybe to to zeroth
%%   order the median difference should be zero, but not to a \kms
%%   level. The median difference is going to depend on at least the
%%   number of points on the positive and negative sides of the galazy to
%%   zeroth order. To first order it will depend on the radial
%%   distribution particularly near the center where the projected
%%   velocity is small. Can you address this?}

\begin{figure}[t]
  \centering
  \includegraphics[width=\columnwidth]{891_2/figs/SG_diff.pdf}
  \caption[Offset between stellar and gas
    velocities]{\fixspacing\label{891_2:fig:SG_offset}Difference
    between stellar and gas velocities after applying a constant
    \val{74}{\kms} offset to the stars. A median of 1 corresponds to
    no average offset between the two population \emph{across both
      sides of the galaxy}.}
\end{figure}

Figure \ref{891_2:fig:SG_offset} shows the relation between stellar
and gas velocities after applying an offset of \val{74}{\kms}. This
offset minimizes the global difference between gas and stellar
velocities across both sides of the galaxy. Based on these results,
the final velocity of each aperture is fixed as the velocity measured
during $\chi^2$ fitting (``stellar velocity'') plus a constant offset
of \val{74}{\kms}. The right hand panel of Figure
\ref{891_2:fig:Swat_vel} shows the final velocities used. We note that
the systematic correction of \val{74}{\kms} is within the total
uncertainty in our velocity as dictated by uncertainties in the
wavelength solution (\val{120}{\kms}, see Chapter \ref{chap:891_1}).

%+++++++++++++++++++=
%% {\bf MAB: The standard is km s$^{-1}$ not \kms. At the end here you
%%   want to discuss the difference between the stars and gas in the left
%%   and right panels compared to each other and the HI envelop. For
%%   example, the asymmetry in the stars is not seen in the gas.}

\subsection{Extinction Model}
\label{891_2:sec:extinction}

During all steps of full spectral fitting
(\S\ref{891_2:sec:SSP_method}) we assume the extinction model of
\citet{Charlot00}, which is described by
\begin{equation}
R(\lambda) = e^{-\tauV \left(\lambda/\val{5500}{\AA}\right)^{-0.7}}.
\end{equation}
This model has a steeper slope than a simple foreground dust screen,
but the authors show it accurately reproduces the ratio of
far-infrared to ultraviolet luminosities, the ratio of \Ha to \HB
luminosities, the \Ha equivalent width, and the ultraviolet spectral
slope of nearby starburst galaxies. We retain the functional
dependence of $\tau \propto \lambda^{-0.7}$ and define two
normalizations, one for gas emission and one for stellar
continuum. Thus, the total optical depth to a particular species is
either
\begin{equation}
\tau_{{\rm cont}}(\lambda) = \tauV \left(\frac{\lambda}{\val{5500}{\AA}}\right)^{-0.7}
\end{equation}
or
\begin{equation}
\label{891_2:eq:tauVB}
\tau_{{\rm em}}(\lambda) = \tauVB \left(\frac{\lambda}{\val{5500}{\AA}}\right)^{-0.7},
\end{equation}
where \tauV and \tauVB are the normalization factors for stellar continuum and
gas emission, respectively.

As described in \S\ref{891_2:sec:SSP_method}, \tauV is a free
parameter of the SSP models that essentially measures the slope of the
continuum. To measure \tauVB (which we need to compute emission
corrections a la \S\ref{891_2:sec:emission_corr}) we use the ratio of
measured \Ha/\HB flux and compare it to the expected value of 2.86
from \citet{Osterbrock89}, assuming case B recombination in a
\val{10^4}{K} gas. Under these assumptions, and given the extinction
law in equation \ref{891_2:eq:tauVB}, we compute
\begin{equation}
\label{891_2:eq:Balmer_extinction}
\tauVB = 4.84 \ln \left(\frac{\Ha/\HB}{2.86}\right).
\end{equation}

The \Ha and \HB line fluxes were measured using the IRAF task FITPROFS
which allows us to deblend the \Ha/[NII] emission feature. Before
fitting the emission lines a ``best fit'' galaxy model is
subtracted. As in \S\ref{891_2:sec:vel} the detailed astrophysics of the
best fit model are unimportant; we only require that the model
accurately match the stellar continuum so that it can be subtracted
from the data. Once the continuum is subtracted the data are smoothed
with a 3 pixel (\val{\asim 350}{\kms}) wide moving average. To
mitigate the impact of bad continuum fits the centroid fitting window
is constrained to be only $\sim 4\sigma$ wide, where $\sigma$ is the
average spectral width (standard deviation) of bright sky emission
lines.

%++++++++++++++++++==
%% {\bf MAB: In the first sentence above do you mean SSP or SPS? I think
%%   the latter. Concerning the 600 \kms wide moving average, is this
%%   equivalent to a boxcar of xx pixels? If so, you might say ``the data
%%   are smoothed with a 600 km s$^{-1}$ (XX pixel) wide moving average,
%%   or boxcar.'' Again, modify \kms to km s$^{-1}$. However, I am not
%%   sure I understand the need for this smoothing and how it reduces the
%%   impact of bad continuum fits. Why? It seems to me you will make the
%%   NII+Ha blending worse which also sounds like it is a problem.}

The relative strength of the two [NII] lines in the \Ha/[NII] complex
is governed by quantum mechanics and we expect the flux ratio
[NII]$_{6585}$/[NII]$_{6549} = 3$. When measuring the \Ha/[NII] lines,
however, we often find [NII]$_{6585}$/[NII]$_{6549} > 3$, which
indicates that the line fit is attributing some of the [NII]$_{6549}$
flux to \Ha and causing the \Ha flux to be overestimated.  This is
likely due to an incorrect de-blending of the \Ha and [NII]$_{6549}$
lines.  We correct for this effect by using the flux of [NII]$_{6585}$
as a ``calibration'' flux (reasonable given its isolation, away from
blending issues of \Ha and [NII]$_{6549}$) and define an \Ha
correction,
\begin{equation}
  \label{891_2:eq:balmer_corr}
  \Delta\Ha = \mathrm{[NII]}_{6549} - \frac{\mathrm{[NII]}_{6585}}{3},
\end{equation}
which is added to the measured \Ha flux.

As mentioned above, measuring \Ha and \HB emission requires first correcting
for \Ha and \HB absorption present in the stellar continuum. In practice the
entire process is iterative because fitting SSPs accurately requires accurate
emission corrections (\S\ref{891_2:sec:emission_corr}), which, in turn, requires
accurate extinction values. We find that the measured Balmer fluxes
and derived emission corrections are stable after only a single
iteration.

%+++++++++++++++
%% {\bf MAB: I would like to understand the issue with the imperfect
%%   continuum subtraction (in the sentence ``This is likely due...'')
%%   and how it alters the NII ratio. In this paragraph, leading up to
%%   the motivation for eqn 10 you want to say that the concept here is
%%   to trust the 6585 NII line because of its greater wavelength
%%   separation from Ha. However, you also need to address wy you think
%%   the continuum subtraction is better for 6585, i.e., why for some
%%   reason the baseline for this line isn't what is causing the problems
%%   with the ratio not equalling 3.

%-----------------
%%   Further, you need to provide the
%%   amplitude of the correction which I expect will vary significatly
%%   with Ha line-strength and height (NII/Ha changes). So I'd like to
%%   know the \% correction to the Ha flux in the mean (and/or median),
%%   and the trends with height, e.g., numbers for 0-0.4 kpc, 0.4-1 kpc,
%%   $>$1 kpc.}

\subsection{Emission Corrections}
\label{891_2:sec:emission_corr}

Many of our apertures show moderate to strong Balmer emission that is
not present in the SSP libraries underlying our galaxy models and
therefore must be subtracted before accurate analyses can be made. To
do this we construct a model spectrum containing only emission from
\Ha, \HB, \Hg, \Hd, and \He.

The basic idea is to first construct a model galaxy produced from fits
where the cores of the Balmer lines were masked. These fits will be
good first guesses of the stellar continuum in the absence Balmer
emission. We then use these fits to remove the stellar continuum and
isolate this emission. Then the two strongest emission lines (\Ha and
\HB) can be used to construct a model containing emission from the
higher-order lines.  Based on the results of \citet{Osterbrock89}, and
assuming case B recombination in a \val{10^4}{K} gas, the ratios of
fluxes for the Balmer series is \mbox{1 : 0.350 : 0.164 : 0.087 :
  0.056} (\Ha : \HB : \Hg : \Hd : \He), thus if we know the flux in a
single Balmer line we can construct a model containing all of these
Balmer lines. In our emission models the width of each line is
dictated by the instrumental resolution measured at the line location
(see Chapter \ref{chap:891_1}), with apertures made from different
sized \GP fibers having different widths.

%++++++++++++++++++++=
%% {\bf MAB: First sentence: I think you mean SPS models (that use
%%   SSPs). I'd like you to explain the notion behind the approach in an
%%   explicit way. The notion is an important idea. The kernel of it is
%%   that Hydrogen Balmer Case B emission strength decreases sigificantly
%%   with higher order, e.g., by more than a factor of 10 between
%%   H$\alpha$ and H$\delta$. In contrast, the equivalent width of the
%%   Hydrogen Balmer absorption in stellar photospheres does not display
%%   this trend, and indeed H$\alpha$ absorption EW is weaker than
%%   H$\beta$. This contrast can be used to our advantage in an iterative
%%   scheme that first masks the cores of the Balmer absorption lines
%%   where the emission is present to provide a first-order estimate the
%%   continuuum. Once subtracted, only the two strongest emission lines
%%   are used to estimate the normalization of the emission and the
%%   attenuation, from which the remaining line-emission is estimated.}

\begin{figure}
  \centering
  \includegraphics[width=\columnwidth]{891_2/figs/TauV_balm.pdf}
  \caption[Height dependence of
    \tauVB]{\fixspacing\label{891_2:fig:tauVB_height}Measured values
    of \tauVB as a function of distance from the midplane. The error
    bars show the uncertainties reported by IRAF from 100 Monte Carlo
    noise iterations. The black shows a linear fit described in
    Equation \ref{891_2:eq:tauVbalm}.}
\end{figure}

This idealized Balmer emission model is then extincted using Equation
\ref{891_2:eq:Balmer_extinction} based on the value of \tauVB as measured in
section \ref{891_2:sec:extinction}. To minimize the impact of aberrant
extinction calculations we compute a height-dependent \tauVB by
fitting a line to the data from all apertures (and thus from all
radii), as shown in Figure \ref{891_2:fig:tauVB_height}. From these data it
is clear that the radial dependence to the vertical trend in \tauVB is
minimal so our grouping of all radii is valid. We find for NGC 891
\begin{equation}
\label{891_2:eq:tauVbalm}
  \tauVB (z) = -0.91 z + 4.15,
\end{equation}
which allows us to compute the extinction in our Balmer emission
models at any height above the midplane.

%----------------------
%% {\bf MAB: Concerning Figure 3: Yuck. I can't tell if the line is a
%%   good fit to the data and whether there is a radial dependence. (You
%%   should say ``a radial dependence to the vertical trend.'') Clearly
%%   we see a radial trend in the stellar absorption later so this result
%%   is somewhat puzzling without some thought and
%%   interpretation. Regarding the figure itself, I'd like to see a
%%   version w/o the error bars. The error bars must be wrong because
%%   they are far larger than the scatter. I would also like to see
%%   moving averages for all pointings as well as for individual
%%   pointings.}

\begin{figure}
  \centering
  \includegraphics[width=\columnwidth]{891_2/figs/emission_comp_zoom.pdf}
  \caption[Spectra before and after Balmer emission
    correction]{\fixspacing\label{891_2:fig:emission_comp}An example
    of Balmer emission correction. The red and blue spectra show an
    aperture with strong Balmer emission (aperture P4.6) before and
    after the Balmer emission model described in
    \S\ref{891_2:sec:emission_corr} is applied.}
\end{figure}

Finally, the emission model is scaled so the \Ha flux matches the \Ha
flux measured in each individual aperture. The data spectra are then
corrected by subtracting the corresponding emission model. Figure
\ref{891_2:fig:emission_comp} shows an example of a spectrum with strong \HB
emission before and after subtracting the Balmer emission model.

In many apertures the blending of the \Ha/[NII] complex causes
imperfect subtraction in this region (as it should, our emission model
does not contain [NII] emission), and in subsequent analysis we do not
fit (i.e., mask) data within \val{\pm 500}{\kms} of \Ha (which
includes both [NII] lines). In addition to \Ha/[NII] we mask other
strong sources of nebular emission ([OIII]$_{4959}$, [OIII]$_{5007}$,
and S2) and sky lines with strong residuals ([OI]$_{6300}$, NaD, and
OI$_{5577}$).

%++++++++++++++++===
%% {\bf MAB: Itemize the lines that you mask -- all of them -- and give
%%   equivalent pixels to 500 \kms at the wavelength extrama. For Figure
%%   4 I can't see anything in this figure so I recommend you show
%%   blow-ups in wave for the Balmer lines from $\alpha$ to $\epsilon$.}

As mentioned above, the best-fit, extinction-value, emission-model
analysis steps are interconnected and at least one iteration is
required to find the ``final'' values.


%\vspace{-5pt}
\section{Conclusions and Future Work}
\label{sec:conclusions}

We found that a learning based approach extracts some interesting patterns,
that cannot be captured by language rules.
We model tokens using dense word vectors and use natural language processing
methods such as
a simple matrix-vector model, feed forward neural network models,
attention models and recurrent models.
These models do not use any information about the language grammar or syntax.
The attention based model performs the best, because it directly connects each
input token to output, and also computes weights for important tokens. It is
the most general of all models, with the most parameters.
We found that by adjusting the vector dimensions and number of layers, we could
reduce overfitting, and get close accuracies for training and test data.
Our top 3 predicted tokens give an accuracy of over 80\% for the cases where
the next token is known (a key or a postitional token), for Linux,
and over 60\% for Twisted.
A study of these vectors reveals a significant clustering of related tokens.

Though we did not use any information about language grammar and syntax, it
would be interesting to combine language rules with our learning based
approach. For example, we could prune our predictions to those that are only
syntactically valid. We could also increase our window size, and jointly
process \texttt{.h} and \texttt{.c} files, to improve the context. Such large
contexts may not scale well with feed-forward model, but recurrent models are
known to perform well with large inputs. We could also try to use language
rules to list out all possible options for next token, and then chain that to a
learning based model to improve the predictions. We could also try to learn
these language rules instead of listing them, by processing a large number of
different projects.


\subsection{Ballista}\label{weapon:ballista}
Stationary Ranged siege Weapon, \passus{50} Reach, DE\\
Shoot (6 AP): 4d12 Piercing Damage\\
Reload (20 AP) The Heavy Stationary Crossbow has to be reloaded after every shot\\
The Heavy Stationary Crossbow has to be operated by three, at most four people - two to three reloading, one shooting\\
Ammunition: Heavy Stationary Crossbow Bolts\\
Size: XXL\\
Cost: 34000 Gold\\


\subsubsection{Heavy Crossbow}\label{weapon:heavyCrossbow}
Weapon, Crossbow, Two-Handed, Regular, Ranged\\
Ammunition: Bolts\\
Size: L\\
Cost: 300 Gold

\textbf{Shoot} \\
3 AP, DE to hit, \passus{50} Reach\\
3d10 + \sfrac{1}{2}\texttimes DE Piercing Damage

\textbf{Reload} \\
4 AP from a back quiver\\
3 AP from a belt quiver\\
The light crossbow has to be reloaded after every shot