\title{\bf Stellar Population Synthesis}

\section{Basics \& Nomenclature}

The theory of stellar structure and evolution predicts how the
luminosity, temperature, and other key parameters defining stars
change over time, and how a population of such stars will change over
time. The theory of stellar atmospheres and observations of stellar
spectra, then tie the stellar parameters to observable spectra and
colors of the stellar population. This overall project of {\it stellar
  population synthesis} connects a star formation history to its
observable results, and can in principle allow observations to be used
to infer quantities such as the total stellar mass, mean stellar age,
metallicity, and other more detailed parameters.

The ingredients of a stellar population synthesis model start with the
stellar initial mass function. The IMF can in principle range from
Salpeter (very ``bottom-heavy'') through to a very ``bottom light''
distribution. There is little evidence that the IMF is constant in all
environments, and some evidence that it does differ in different
environments.

Stellar structure and evolution models yield stellar parameters like
luminosity and effective surface temperature of the population as a
function of time. These results are usually expressed as a series of
{\it isochrones} showing the position of stars in the population as a
function of time. Uncertainties in these models arise. Even on the
main sequence, three-dimensional effects on stellar evolution, such as
convection, rotation, and stellar binarity, are at best approximately
included in isochrone modeling.  Post main sequence phases suffer from
this problem even more greatly. Mass-loss due to winds is uncertain
and affects the final fate of the stars.  Modeling of
thermally-pulsating asymptotic giant branch (TP-AGB) stars is very
uncertain (partly due to winds but also modeling uncertainties and a
paucity of individual stars for calibration). The TP-AGB stars cause
particular uncertainty for NIR observations of intermediate age
populations. The dependence of the temperatures of horizontal branch
stars on stellar parameters is also uncertain (again likely due to
winds).

Stellar atmosphere theory and stellar libraries yield spectra as a
function of these parameters. The theoretical models can be computed
for any stellar parameters in a uniform fashion, but do not always
include all the relevant atomic and molecular lines, or correct
consideration of microturbulent velocities, convection, departures
from local thermodynamic equilibrium, or the spherical
geometry. Empirical libraries, on the other hand, tend to be
heterogeneous in their observational properties, suffer from
spectrophotometric calibration issues, and sparsely cover the
necessary space of temperature, surface gravity, metallicity, and
abundance space.  Again, the major uncertainties arise for rare
populations, and particularly post main sequence populations, but also
metal poor and/or $\alpha$-rich populations.

A population with a single age and abundance is known as a {\it simple
stellar population} (SSP). Its spectrum can be expressed as:
\begin{equation}
f(t, Z) \int_{m_{\rm low}}^{m_{\rm high}(t)} \dd M \Phi(M) f_{\rm
star}(t, M, Z)
\end{equation}
We often need to model a more complicated star formation and chemical
evolution history (sometimes using the post main sequence evolution in
the models to self-consistently predict the chemical enrichment of the
ISM). Any such history may be written as a sum of SSPs, and the
resulting spectrum is the corresponding sum of the individual SSP
spectra.

In many galaxies, the effects of dust on the spectrum cannot be
ignored. Dust is mixed into the interstellar medium gas and it
attenuates the light in a wavelength dependent manner, preferentially
scattering blue light and transmitting red light. In modeling emergent
spectra from galaxies, it appears necessary to account for the dust's
distribution, which is preferentially around star forming, gas-rich
regions.

Broad trends from stellar population synthesis are:
\begin{itemize}
\item Stellar populations start blue, with spectra that do not
have features useful for measuring metallicity.
\item Stellar populations evolve redward after the cessation of star
formation, during which time their Balmer absorption features become
weaker (on time scales of a few 100 million years) and their 4000 \AA\
break grows stronger (on about a billion year time scale).
\item When they are red, their spectra are similar to $K$ stars, since
they are dominated by $K$ giants; these spectra are
metallicity-sensitive, but with a degeneracy with age.
\item At early times, the populations have low mass to light ratios;
as the stellar population ages, it fades and the mass to light ratio
increases up to higher than solar values.
\item Low mass stars contribute a large fraction of the mass but a
small fraction of the light, which means that considerable mass can
reside in old stellar populations (if there is a younger population to
mask them) or in low mass stars in the IMF (if there are massive stars
to mask them).
\end{itemize}

Stellar population synthesis methods are commonly used to infer
galactic star formation histories and other physical properties.
In broad strokes, the galactic properties are parametrized, and then
parameters are varied to fit some set of observable quantities. There
is considerable variation among investigators as to the quantities
used and the parametrizations.

The {\it stellar mass} is almost always a quantity of interest. It is
defined as the mass currently in stars and stellar remnants. Of the
total mass in stars that have formed, only of order half the mass will
remain as stars or remnants after a few billion years, and about a
quarter of that is in the (extremely low luminosity) remnants.

The most ambitious approaches attempt constraints on the full star
formation history and fit to a detailed observed spectrum. A proper
analysis must marginalize over stellar population uncertainties and
dust effects and over spectrophotometric calibration uncertainties. In
addition, the presence of interstellar and AGN emission lines needs to
be accounted for, either by excluding their wavelengths from the fit
or including the lines explicitly.

Other approaches simplify the problem, usually in an attempt to
regularize the model space in ways thought to be reasonable, or in an
attempt to mitigate observational uncertainties (without performing an
explicit marginalization).

The classic {\it Lick index} analysis technique, commonly used for
elliptical galaxies since the 1980s, employs both approaches. Lick
indices are defined for 21 features between 4000--6500 \AA. They are a
form of {\it equivalent width}. Equivalent widths measure:
\begin{equation}
{\rm EW} = \frac{f_{\rm feature}}{f_{\lambda, {\rm continuum}}},
\end{equation}
the total absorption or emission of a feature ($f_{\rm feature}$, in
units of flux) relative to some local definition of the continuum upon
which the feature is imprinted ($f_{\rm continuum}$, in units of flux
density). Usually, the flux density in question is in $f_\lambda$
units and the equivalent width is expressed in units of Angstroms
(thus the terminology ``width,'' which does not in all cases imply a
measure of actual width in wavelength space). Often, the continuum
level is measured using side bands slightly blueward and redward of
the feature.

Equivalent widths, and specifically Lick indices, have some attractive
qualities. Because they are relatively local measurements in
wavelength, they are insensitive to dust and to spectrophotometric
error. In the case of Lick indices, the index measurements were
performed on stars with well-calibrated properties, allowing the
corresponding measurements in galaxies to be tied directly to the
stellar models.

However, equivalent widths involve defining a continuum, which can be
ambiguous in regions with other features.  In addition, for Lick
indices specifically, the stellar observations were taken at
relatively low resolution, which needs to be accounted for in studying
low velocity dispersion galaxies and higher resolution spectra.

The Lick indices were chosen by hand for their sensitivity to specific
atomic features. They are in the blue regime (between 4000 and 5300
Angstroms), due to the technology available at the time of their
original definition.  The Lick index analysis proceeds by measuring a
set of indices associated with the Balmer absorption features
(measuring the fraction of young stars), Fe features (which arise in a
complex suite of lines), and the Mg $b$ feature. The Balmer and Fe
features require some correction for emission line contamination. The
indices are then compared to a simple stellar population model
characterized by its age, metallicity, and $\alpha$-enhancement. Since
galaxies do not have simple stellar populations, the resulting
parameters at best express some weighted average of the underlying
star formation history; in the case of the standard Lick analysis, the
ages are always smaller than the mass-weighted age estimate.  Other
uncertainties are known to affect the existing Lick analyses, to do
with the stellar population modeling accuracy; most significantly, old
stellar populations contain an uncertain number of blue horizontal
branch stars, which confuse the interpretation of the Balmer
absorption features.

Between full spectral analysis and Lick index analysis lies a large
space of possible analyses that has been explored by many
investigators. Some important facts revealed by these analyses are as
follows:
\begin{itemize}
\item Age and metallicity both have similar effects on spectral
features, both broad band and for individual lines. Older ages lead to
a greater dominance of the red giant branch, and thus redder colors
and stronger absorption features. High metallicity leads to lower
effective temperatures of stars, and also strong absorption at fixed
temperature, both effects also producing redder colors and stronger
absorption features.
\item Stellar mass-to-light ratios depend to a surprising degree just
on the color of the stellar population; greater age, greater
metallicity, and greater dust all affect the broad band flux by making
it redder and fainter (relative to mass), in similar proportions to
each other.
\item A definition $D_n(4000)$ for the 4000 \AA break is informative
as to stellar population age (though it carries metallicity dependence
as well).
\end{itemize}

Beyond metallicity, stellar population analyses can be sensitive to
individual abundances as well. Most commonly, these are expressed in
term of [$\alpha$/Fe], the $\alpha$-element abundance relative to
iron. In contrast to observations of the interstellar medium, typical
observations of stellar populations are most sensitive to Mg rather
than the more abundant oxygen, due to the lack of atomic oxygen lines
in stars in the optical. In the Milky Way, it is known that oxygen and
magnesium do not, however, always vary together, so Mg as a proxy for
other $\alpha$ elements is not perfect.

A special case for the use of stellar populations is the inference of
recent star formation, as directly traced by O and B
stars. Ultraviolet emission can be used to trace the star formation
rate, preferably far UV ($\sim$ 1500 \AA), though near near UV ($\sim$
2500 \AA) or even $u$-band is occasionally used. Such measures need to
be dust-corrected. In the UV, this is often done using the FUV to NUV
ratio (since in principle this ratio is fixed for hot stars). If
optical imaging is available, one can estimate reddening using stellar
population analysis of the optical bands. If infrared imaging is
available, the IR flux directly traces the extincted light, modulo the
geometric anisotropy of the UV extinction. In this last case, a
weighted sum of the UV and infrared luminosity can yield a reliable
star formation rate estimate. The mid-IR is thought to be more
reliable in this regard, since the colder dust in the far-IR can be
heater by old stellar populations.

With spectra, star formation averaged over longer time scales is
possible. For example, star formation over a few hundred million year
time scales is traced by the Balmer lines.  A very special cases
arises for K$+$A, sometimes called E$+$A, or post-starburst,
galaxies. Such galaxies show few traces of star formation on million
year time scales (as traced usually by H$\alpha$ interstellar
emission), but do show strong star formation on a few hundred million
year timescales (as traced by Balmer absorption). These galaxies
likely experienced a large burst of star formation a few hundred
million years ago, which is now over.

Interpretation of star formation rates, especially but not only at low
values, requires care.  Old stellar populations do emit some UV light,
depending on their population of horizontal branch stars; in practice,
measuring specific star formation rates below about $10^{-11}$
yr$^{-1}$ is not possible.  Both ultraviolet and near-infrared
emission can be powered by AGN as well, which near the centers of
galaxies can be a confusing factor as well.

There are a handful of cases for which stellar population histories
can be derived directly from resolved stellar populations. Stellar
clusters in the Milky Way are one case. To a certain extent, the
population of stars with parallaxes in the Milky Way can also be used
in this way. Some nearby galaxies (M31, M33, and others) have resolved
stellar populations from space, and these cases can be studied from
the isochrones. Since they also have broad band and spectroscopic
measurements similar to more distant galaxies, they can provide a
calibration between the two approaches.

\section{Commentary}

In principle, stellar population analysis requires marginalization
over all of the uncertain parameters that characterize the stellar
population modeling. These uncertainties are:
\begin{itemize}
\item Stellar IMF
\item TP-AGB phases
\item Blue stragglers
\item Extreme horizontal branch stars
\item Effects of convection on evolution
\item Mass-loss through winds
\item Effects of binarity on evolution
\item Stellar atmospheres models \& libraries
\item Dust and dust geometry
\end{itemize}

\section{Key References}

\begin{itemize}
  \item
    {\it Old stellar populations. 5: Absorption feature indices for
    the complete {L}ick/{IDS} sample of stars}, \citet{worthey94}
  \item
    {\it Modeling the Panchromatic Spectral Energy Distributions of Galaxies}, \citet{conroy13a}
\end{itemize}

\section{Important numbers}

\begin{itemize}
\item $M_{\odot} = 1.989 \times 10^{30} {\rm ~kg} $
\item $R_{\odot} = 6.955 \times 10^{8} {\rm ~m} $
\item $T_{\odot}{\rm (surface)} = 5500 {\rm ~K} $
\item $T_{\odot}{\rm (core)} = 1.5 \times 10^7 {\rm ~K} $
\item $L_{\odot} = 3.828 \times 10^{33} {\rm ~erg} {\rm ~s}^{-1}$
\end{itemize}

\section{Order-of-magnitude Exercises}

\begin{enumerate}
\item Estimate the ratio between star formation rate and FUV flux
    around $\lambda \sim 1200$ \AA.
    Assume that the luminosity in the FUV band of an O-star
    is $\sim 10^{34}$ erg s$^{-1}$ \AA$^{-1}$ at that wavelength (a
    very approximate number for the O2 star BI 237 in the Large
    Magellanic Cloud, according to the atlas of \citealt{smith12a}).
\item Estimate the difference in mass-to-light ratio in the optical
    between a 200 million year old and 10 billion year old stellar
    population. Assume that the solar mass stars (which dominate the
    flux of the older population) spend about 10\% of their time at
    the tip of the red giant branch and that the distribution of stars
    along the red giant branch is constant per unit magnitude.

\begin{answer}
At 200 Myr in age, the stars in stellar population stars are mostly in
main sequence. The luminosity is dominated by late-type B stars of
about 5 $M_\odot$, whereas the mass is dominated by low mass
stars. The mass-to-light ratio may be calculated as:
\begin{equation}
\frac{M}{L} = \frac{\int_{0.08M_\odot}^{5 M_\odot} {\rm d}M M \Phi(M)}
{\int_{0.08M_\odot}^{5 M_\odot} {\rm d}M L(M) \Phi(M)}
\end{equation}
where $\Phi(M)$ is the initial stellar mass function. If we assume
$(L/L_\odot) = (M/M_\odot)^4$ and $\Phi\propto M^{-2.35}$, then in
solar units:
\begin{equation}
\frac{M}{L} = \frac{\int_{0.08}^{5} {\rm d}x x^{-1.35}}
{\int_{0.08}^{5} {\rm d}x x^{1.65}}
\end{equation}
which evaluates to $M/L\sim 0.2$.

Now, for the 10 Gyr stellar population, solar mass stars are just
entering the red giant branch. The luminosity of solar mass stars in
the red giant phase is $L_{\rm RGB} \sim 10^{3}L_{\odot}$. Solar mass
stars spend 10\% of the main sequence lifetime on the RGB, meaning
that the set of stars there will be those that leave the main sequence
within about 10\% of the total lifetime (1 Gyr). Let us call the range
of masses this corresponds to $\Delta M(t_\odot)$. We can write the
mass to light ratio as:
\begin{equation}
\frac{M}{L} = \frac{\int_{0.08 M\odot}^{M_\odot} {\rm
d}M M \Phi(M)}{\Phi(M_\odot) \Delta M(t_\odot) \langle L_{\rm
RGB}\rangle}
\end{equation}
We can determine $\Delta_M(t_\odot)$ as follows, by relating the range
in time to a range in mass:
\begin{equation}
\Delta M (t) \sim \Delta t \left|\frac{{\rm d}M}{{\rm d}t}\right|
\end{equation}
and differentiating the relationship
\begin{equation}
\left(\frac{t}{t_\odot}\right) = \left(\frac{M}{M_\odot}\right)^3
\end{equation}
to show
\begin{equation}
\left|\frac{{\rm d}M}{{\rm d}t}\right|
= \frac{M_\odot}{3 t_\odot} \left(\frac{M}{M_\odot}\right)^4
\end{equation}
and so:
\begin{equation}
\Delta M (t) \sim \frac{1}{3} M_\odot \frac{\Delta t}{t_\odot} \left(\frac{M}{M_\odot}\right)^4
\end{equation}
Then we can calculate:
\begin{equation}
\langle L_{\rm RGB} \rangle =
\frac{\int_{L_\odot}^{10^3 L_\odot} {\rm d}L N(L) L}
{\int_{L_\odot}^{10^3 L_\odot} {\rm d}L N(L)}
\end{equation}
where $N(L)\propto 1/L$ (constant per unit magnitude), so:
\begin{equation}
\langle L_{\rm RGB} \rangle =
\frac{\int_{L_\odot}^{10^3 L_\odot} {\rm d}L}
{\int_{L_\odot}^{10^3 L_\odot} {\rm d}L L^{-1}} \sim \frac{1000}{3\ln
10} L_\odot \sim 140 L_\odot
\end{equation}
Plugging in and using solar units:
\begin{equation}
\frac{M}{L} = \frac{\int_{0.08}^{1} {\rm
d}x x^{-1.35}}{(1/3) (140) (0.1)} \sim 1
\end{equation}
In fact, this is an underestimate; for old populations the
RGB tends to be more heavily populated per unit magnitude near its
base, which increases the mass-to-light ratio by a factor of a few.

An important point is that although the old population is dominated by
solar mass stars, and also has a mass-to-light ratio similar to solar
values, this is the consequence of the balance between the numerator,
dominated by the lower stellar masses, and the denominator, dominated
by the post-main sequence lifetime and luminosity distribution. Thus
the rough agreement in mass-to-light ratio is a coincidence.
\end{answer}
\item Using a Salpeter initial mass function, and assuming that
$L\propto M^4$ determines both the luminosity and lifetimes of the
stars, calculate how the stellar luminosity varies as a function of
time expected at early times (e.g. $\sim 100$ Myr), before the red
giant branch population of stars becomes important. Do not worry about
the absolute value of the luminosity, just its time dependence.

\begin{answer}[Author: Nicholas Faucher]
The lifetime of a star with mass $m$ can be estimated by comparing to
the lifetime of the Sun, $\tau_{\odot} \approx 10^{10} \, yr$, as
$\tau \approx \frac{m}{L} \, \tau_{\odot}$, where $m$ and $L$ are the
mass and luminosity of a star in solar units. Assuming a mass-to-light
ratio of $L \propto m^4$, we can rewrite this equation in terms of
mass only:
\begin{equation}
\tau \approx \frac{1}{m^3} \, \tau_{\odot}
\end{equation}
Solving this equation for $m$ sets the upper limit on the masses of
stars in a population at time $\tau$. Assuming a Salpeter IMF, which
asserts that the number of stars in a stellar population with mass
between $m$ and $m+dm$ is proportional to $m^{-2.35}$, we can
determine the time dependence of a stellar population's luminosity. To
do this, we also assume that each star has constant luminosity until
the end of its lifetime, at which point it has no luminosity. Then the
total luminosity is just the integral of the stars
\begin{equation}
L(t) \propto \int_{0.08}^{\big( \frac{10^{10}}{t} \big) ^{\frac{1}{3}}} m^{-2.35} \, m^4 \, dm
\end{equation}
The term corresponding to the lower limit on the integral is
negligibly small ($\sim 10^{-4}$) and so we get
\begin{equation}
L(t) \propto t^{-0.883}
\end{equation}
This dependence should hold at early times, when post-main sequence
stars are not dominating the luminosity. As the population ages past a
billion years, the luminosity is dominated by red giant branch stars
and this dependence changes (slowing down generally).
\end{answer}

\item What is difference between the mass-to-light ratios of two
10-billion-year-old stellar populations, one with a Salpeter IMF and
one with an IMF which is Salpeter above $M=0.7M_\odot$ but has
$\Phi(M) \propto$ constant at lower masses?
\end{enumerate}

%\section{Analytic Exercises}
%
%\begin{enumerate}
%\end{enumerate}

\section{Numerics and Data Exercises}

\begin{enumerate}
\item There is
a \href{https://python-fsps.readthedocs.io/en/latest/installation/}{Python
interface} to the Flexible Stellar Population Synthesis
(FSPS; \citealt{conroy09a}) software, which is one of several
libraries that exist for this purpose. Install this package and (using
the scant available documentation!) run it to produce spectra for
dust-free populations with a range of ages and
metallicities. Specifically, do 25 models, with five metallicities and
five ages spaced logarithmically between $Z/Z_\odot = 0.01$ and
$Z/Z_\odot = 2$, and ${\rm age} = 10^8$ years and ${\rm age} =
10^{10}$ years. Then create the same set of models with a modest
amount of dust reddening (say around $A_V \sim 0.5$). Plot the spectra
for comparison with each other in the UV through near-IR
range. Warning: this software is incredibly slow.
\item For the same set of models as the first question, use FSPS to
project the spectra onto the $u$ and $r$ filters. Then plot the
mass-to-light ratio in the $r$-band as a function of $u-r$ color for
all models.  Also plot $g-r$ versus age. In each plot, distinguish
between the no-dust and dust cases.
\item For the same set of models as the first question, use $D_n$4000,
and plot it versus age, again distinguishing between the no-dust and
dust cases.
\item For the same set of models as the first question, calculate
the Lick Mg $b$ and the $\langle$Fe$\rangle$ indices (the latter being
the mean of Fe5270 and Fe5335). Plot the mapping of this set
of models into the Lick index space as two grids (one for each dust
case).
\end{enumerate}

\bibliographystyle{apj}
\bibliography{exex}


%!TEX root = main.tex

\chapter{Sampling, waveshaping, and non-linearity}
\label{Waveshaping}

\begin{center}
\begin{figure}[h!]
\tikzset{concept/.append style={fill={none}}}
\begin{tikzpicture}
  \path[mindmap,concept color=black,text=black]
    node[concept] {Sampling}
    [clockwise from=0]
    child[concept color=red!50!black] {node[concept] (rec) {recording} }
    child[concept color=green!80!black] {node[concept] (pla) {playback} }
    %   [clockwise from=90]
    %   child { node[concept] {algorithms} }
    %   child { node[concept] {data structures} }
    %   child { node[concept] {pro\-gramming languages} }
    %   child { node[concept] {software engineer\-ing} }
    % }
    child[concept color=blue] { node[concept] (ram) {in RAM vs. from Disk}[clockwise from=-30]}
    child[concept color=red] { node[concept] (gra) {granular} }
    child[concept color=orange] { node[concept] {Waveshaping and Distortion} };

\begin{pgfonlayer}{background}
	% \draw [draw=green,fill=black, decorate,decoration=circle connection bar]
    \draw [circle connection bar]
    % \path (rec) to[circle connection bar] (pla)
      (rec) edge (pla)
      (gra) edge (pla)
      (ram) edge (pla)
      ;
  \end{pgfonlayer}

\end{tikzpicture}
\caption{Lecture Contents}
\end{figure}
\end{center}

% \section{Notizen}

% Waveshaping generell.

% Evt. Subtraktiver Synth am ende.

% Zusammenhang waveshaping, distortion. lookup table, sampling, wavescanning.

% Waveshaping = modulation \cite[p.~257]{farnell_designing_2010}

% chebyshev

% \glqq{}intermod. distortion \grqq{} , vgl. miller puckette, \\
% http://msp.ucsd.edu/techniques/latest/book-html/node78.html

% middle term! ( (a+b)**2 = a**2 +2ab +b**2 )

% beispiele:
% sinus
% vllt:\\
% dyn. non-linear functions

% \section{Uebersicht}
% Zunächst: Sampling, dann lineare transfer function.

% \begin{enumerate}
% 	\item übersicht: fragen wies geht, wie ist es mit Max/MSP?
% 	\item HÜ ankündigen
% 	\item neue abstraction: z-1
% 	\item Raetsel
% 	\item Wo letztes mal stehngeblieben? Poly syth fertig?
% 	\item linearität erklären. Nun Nichtlinearität.
% 	\item wavetable/lookup wiederholung
% 	\item Lookup als waveshaping/distortion
% 	\item waveshaping durch processing vs. durch lookuptable
% 	\item durchrechnen
% 	\item chebyshev
% 	\item Sampling (Ram nicht Ram)
% 	\item send and receive von GUI f. Hausübung
% \end{enumerate}

\section{Waveshaping}

 \link{https://colab.research.google.com/github/hrtlacek/dspCourse/blob/master/notebooks/01\_sampling\_non-lin.ipynb}{Notebook for this Section}
\link{https://www.shadertoy.com/view/ws3fD4}{Shader for this Section}

Wikipedia quote, page ``waveshaper'':\\
\glqq{}The mathematics of non-linear operations on audio signals is difficult, and not well understood.\grqq{}
Waveshaping means distortion. It adds overtones, take a look at figure ~\ref{fig:waveshapedSIne}.

\begin{figure}[h!]
	\centering
	\includegraphics[width=11cm]{waveShapedSine.png}
	\caption[Wave shaped sine oscillator]
	{A sine wave has been generated and waveshaping was applied to add overtones.}
	\label{fig:waveshapedSIne}
\end{figure}

\begin{figure}[h!]
	\centering
	\includegraphics[width=11cm]{tanhTime.png}
	\caption[Distorted sine, time domain]
	{The same as the spectrogram above, but in the time domain. We can see the input sine wave and the slightly distorted output. It may look like just the amplitude has changed, but the sine's actual \textit{shape} has changed slightly}
	\label{fig:tanhTimeDom}
\end{figure}

\subsection{The simplest case: a linear Transfer function. } % (fold)
\label{sub:linearTrans}
See \ref{fig:linfunct}. A linear transfer function is used as a lookup table for a sinosoidal input.

\newpage

\begin{figure}[h]
	\begin{center}
		\includegraphics[scale = 1]{img/waveShapingVisual.png}
		\caption{Linear Transfer function}
		\label{fig:linfunct}
	\end{center}
\end{figure}
A transfer function in the sense of a waveshaper (a ``transfer function'' might also mean frequency response in other contexts) is a simple look-up function. \
Waveshaping means to use an input wave to \textit{look up} values in a table or function. A linear transfer function, let's call it $l$, can result in no change, for example, it might return $l(x)=x$. \
This means, that whatever value we pass in, we get the same value out.\
Other linear transfer functions might \textit{only} change the amplitude. For example $f(x)=x \cdot \frac{1}{2}$. That doesn't seem very interesting. But it might explain the term ``linear''. A transfer function is linear if it looks like a line if we plot it. Look at figure \ref{fig:linears}.

\begin{figure}[h!]
	\centering
	\includegraphics[width=15cm]{linearFunctions.png}
	\caption[Linear Transfer functions]
	{A couple of linear transfer functions and their corresponding effects demonstrated using a sine wave. From left to right: multiplication by 0.5, so attenuation by about 6dB, inversion, and the ``do-nothing''-function.}
	\label{fig:linears}
\end{figure}

Non-liner transfer functions behave differently. They map their input to other values, such as $f(x) = x^2$. And if we plot then, they don't look like a line.  You can also look at figure \ref{fig:farnellWaveShaping} in order to understand what's happening. We again see a linear transfer function but also a non linear one.
\begin{figure}[H]
	\centering
	\includegraphics[width=13cm]{waveshapingVizFarnell.png}
	\caption[farnell wave shaping visualization]
	{A waveshaping visualization taken from \cite{farnell_designing_2010}}
	\label{fig:farnellWaveShaping}
\end{figure}

But let's get back to our square function, since it's simpler and we will find some surprising results when analyzing it. Let's first simply plot it too.

\begin{figure}[H]
	\begin{center}
		\includegraphics[width = 14cm]{img/squareFunction.png}
		\caption{The function $f(x)=x^2$}
		\label{fig:square}
	\end{center}
\end{figure}

% subsection subsection_name (end)

\video{
What does applying a curve to every pixel of a video or image do? Is this even something people do? Of course! Think of contrast curves, below is an example from photoshop. Beware that video is working with unipolar input values and audio with bipolar inputs.
\begin{center}
  \includegraphics[width=8cm]{photoshop.png}
  \captionof{figure}{Contrast curve in photoshop}
  \label{fig:photoshop}
\end{center}
}

\subsection{Simple non-linearity: \(X ^2\)} % (fold)
\label{sub:nonLinearTrans}

So let's analyze what happens if we use this function for waveshaping. Here it is again:

\begin{equation}
f(x) = x ^ 2
\end{equation}

% \fbox{
%   \parbox{\textwidth}{
%     Ein polynom geradzahliger ordnung \(n\) als Transferfunktion produziert immer alle geradzahligen obertöne von \(n\) bis 0, exklusive der grundfrequenz (da ja auch ungerade, 1 ist eine ungerade zahl).\\
% Ein polynom ungeradzahliger ordnung \(n\) als Transferfunktion produziert immer alle ungeradzahligen obertöne von \(n\) bis 1, also der grundfrequenz.
%   }
% }
Let's simply listen to what's happening, building it in Max:

\begin{figure}[H]
	\begin{center}
		\includegraphics{img/pd_square.png}
		\caption{The square function in pure data, using a 100Hz sine as a test signal. What do you hear?}
		\label{fig:squarePd}
	\end{center}
\end{figure}

And we can simply plot what happened if we apply the function before also trying to understand analytically:

\begin{figure}[H]
	\begin{center}
		\includegraphics[width = 14cm]{img/sinSquared.png}
		\caption{Applying the square function to an input sine wave.}
		\label{fig:sinSquared}
	\end{center}
\end{figure}

Weird, the input seems to double in frequency (did you hear that?). Let's try to understand what's happening.\

So we calculate what happens if we send a cosine through this function, so let's take:

\begin{equation}
x = cos(\omega)
\end{equation}
wit arbitrary $\omega$. We can just ignore $\omega$ here for a while. Usually, there should be some indexing variable in the cosine function if we want to describe an oscillator that moves over time, but let's also skip that.\\
So applying our square function we of course get:
\begin{equation}
y = cos(\omega)^2
\end{equation}
This again results in:
\begin{equation}
y = cos(\omega) \cdot cos(\omega)
\end{equation}
So far so trivial. Note that a multiplication of two oscillators is called \textit{Amplitude Modulation} (actually, in this case we encounter ``Ring Modulation'', but let's ignore that also), and we know things about Amplitude modulation, namely:\

\fbox{
  \parbox{\textwidth}{
  When multiplying two oscillators, we get sum and difference of the two input frequencies. (And the whole output is attenuated by 6dB)
  }}
The above statement in equation form:
\begin{equation}
	cos(a)\cdot cos(b) = \frac{cos(a+b) + cos(a-b)}{2}
\end{equation}

We could also have looked up this \textit{trigonometric identity}.
This means for our experiment with our cosine squared:

\begin{equation}
y = \frac{cos(\omega+\omega) + cos(\omega-\omega)}{2}
\end{equation}
So:
\begin{equation}
y = \frac{cos(2 \cdot \omega) + cos(0)}{2} = \frac{cos(2 \cdot \omega )}{2}+\frac{1}{2}
\end{equation}

We arrive at the same result!
But is this true for every input? That would mean we just built a frequency shifter, did we? No. Waveshaping is much more complicated.\\

\begin{mdframed}[backgroundcolor=black!10,rightline=false,leftline=false]

This is immediately obvious when we try to do the same with two oscillators:
\begin{equation}
x = cos(\omega_1)+cos(\omega_2)
\end{equation}
then
\begin{equation}
y = (cos(\omega_1)+cos(\omega_2) ) ^2
\end{equation}
\begin{equation}
y = cos(\omega_1)^2+cos(\omega_2)^2+2\cdot cos(\omega_1) \cdot cos(\omega_2)
\end{equation}

And finally:
\begin{equation}
	y = \frac{cos(2 \cdot \omega_1)}{2} + \frac{1}{2} + \frac{cos(2 \cdot \omega_2)}{2} +\frac{1}{2} + 2 \cdot (\frac{cos(\omega_1+\omega_2) + cos(\omega_1-\omega_2)}{2})
\end{equation}

% \textbf{The point here is not to know this result by heart}, the point merely is that it's getting pretty complex.

\end{mdframed}

\subsection{How can waveshaping be implemented?} % (fold)
\label{sub:how_can_waveshaping_be_implemented_}

% subsection how_can_waveshaping_be_implemented_ (end)
Take a look at figure \ref{fig:tableVsCPU}. What do you think is happening?
On the left side, we see waveshaping as we did it above, using a mathematical function, in this case the tangens hyperbolicus, to distort our signal. On the right side, we see a table that contains the authors desperate attempt to draw the same function with the mouse. The results are theoretically equivalent (if the function in the table was correct), but what are the advantages and disadvantages of the two approaches?
Also, be sure to understand what the addition of 1 and the multiplication with 50 does on the right side. Hint: the array has 100 points.

\begin{figure}[H]
	\begin{center}
		\includegraphics[width = 14cm]{tableVsCPU.png}
		\caption{Left: using a mathematical function to calculate the output. Right: using a table to look up the output.}
		\label{fig:tableVsCPU}
	\end{center}
\end{figure}

\subsection{How is Waveshaping related to other techniques?}
\subsubsection{Sampling}
If we take a look at figure \ref{fig:RamFilePlayback}, we see that we play a sound file by accessing a buffer (wavetable) using an index, an oscillator. This is effectively the same setup as we would build for distorting an input sound. Also take a look at figure \ref{fig:identity}, which showing us that waveshaping and wavetable synthesis are identical.

\begin{figure}[H]
	\centering
	\includegraphics[width=11cm]{identityWaveshaping.png}
	\caption[farnell waveshaping identity]
	{Picture taken from \cite{farnell_designing_2010}, showing the identity of waveshaping and wavetable synthesis}
	\label{fig:identity}
\end{figure}

\subsubsection{Modulation}
While we will talk about modulation in a separate chapter, let's loosely define amplitude modulation (AM) as the multiplication of two oscillators and frequency modulation (FM) as varying the frequency of an oscillator using another oscillator.\
So, as we have also seen above, AM looks like this:
\begin{equation}
	y = sin(a)\cdot sin(b)
\end{equation}

and FM looks like this:

\begin{equation}
	y = sin(sin(a))
\end{equation}

in practice, the a and b terms are a bit more complicated, but we will look at this later. That certain cases of AM are identical to waveshaping has been shown above, think about the square function again.
This of course does not mean that waveshaping can do everything AM can do and it does not mean that AM can achieve everything that waveshaping can. This should just show that we can understand the techniques from the perspective of another.\
What about FM? Well if our lookup function we use for waveshaping is a sine wave, we arrive at the exact same equation as how we defined FM above. Again, practically speaking, the results we get with these two techniques are very different, but we can see the connections.

\subsection{Why is Waveshaping useful?}
The output spectrum is dependent on the input amplitude. This makes it easy to create complex evolving spectra.

\subsection{What are the problems with waveshaping?}

Waveshaping adds overtones. When we build a waveshaper, we have to be aware of aliasing. Take a look at figures ~\ref{fig:clipped1} and ~\ref{fig:clipped2}. Sinewaves have been amplified and clipped here.

\begin{figure}[h!]
	\centering
	\includegraphics[width=11cm]{clippedSine.png}
	\caption[clipped sine wave]
	{A sine wave was generated and clipped. Clipping is a form of waveshaping which adds many overtones. Note how high frequencies fold back into the lower parts of the spectrum because they exceed the Nyquist-rate.}
	\label{fig:clipped1}
\end{figure}

\begin{figure}[h!]
	\centering
	\includegraphics[width=11cm]{clippedSine2.png}
	\caption[clipped sine wave 2]
	{Again, a sine wave, this time with a higher frequency to begin with. Extreme clipping has been applied by boosting the input amplitude. The aliased overtones are all over the place, even below the input frequency.}
	\label{fig:clipped2}
\end{figure}

In Max we could achieve this like in figure \ref{fig:pdClipping}.

\begin{figure}[H]
	\begin{center}
		\includegraphics{img/pdSineClipping.png}
		\caption{Clipping an amplified sine wave in Max}
		\label{fig:pdClipping}
	\end{center}
\end{figure}

What does the output look like? Let's not only look at the spectra but also at the time signal:

\begin{figure}[H]
	\begin{center}
		\includegraphics[width = 14cm]{sineClipTime.png}
		\caption{An amplified and clipped sine wave in the time domain.}
		\label{fig:timeClip}
	\end{center}
\end{figure}

We see that we can arrive at a square-wave like result, but this square-wave is not anti-aliased.\\

The problem of aliasing in waveshaping is usually treated by over-sampling. This does not solve the problem but lessens it significantly resulting in cleaner, arguably better sound. Oversampling means that, if we work at a sample-rate of 44.1kHz, the input is up-sampled, essentially interpolated, to be at a sample-rate of 88.2kHz. Then the waveshaping is applied, leaving room for high frequencies up to 44.1kHz. Using a lowpass filter, high frequencies over 22.1kHz are then attenuated as much as possible, in order to be able to down-sample again to reach our initial sample-rate of 44.1kHz. \\
To state it more simple: Waveshaping is usually encapsulated in a process that runs at higher sampling rates in order to lessen aliasing.

% Wieso ist waveshaping praktisch? Amplitudenabhängigkeit d. spectrums.
% Wieso ist waveshaping verwandt mit modulation, sowohl FM, PM als auch AM? Am: siehe \(x^2\). FM: siehe \(f(x)=cos(x)\). Auch kann letztendlich eine transferkuntion in cos/sin bestandteile zerlegt werden um zu einer menge an frequenzmodulationen anzukommen, bzw kann der wavetable als polynom angenähert(o. Taylor entwicklung) werden um bei AM anzukommen.

\section{Sampler}
In pure data (but also in general) we can choose to play a sound from RAM or more or less\footnote{the data played from disk needs to be cached also} directly from the hard disk. Both Approaches have their different use-cases.\\

\video{In video, we need to make the same decision essentially. We can choose to buffer as much as we can on the VRAM of the graphics card or rather play from disk. Also different codecs specialize on balancing the load differently. The HAP codec for example tries to only push as much of the load to the hard disk and as little as possible to the CPU (which is decoding the video for playback). In times of SSDs this is a very good (and scalable) method to push a lot of data to playback in realtime.}
\textit{Work in progress.}

\begin{figure}[H]
	\begin{center}
		\includegraphics{img/sampler.png}
		\caption{Playback an audio file from disk.}
		\label{fig:simpleSampler}
	\end{center}
\end{figure}

% \begin{figure}[H]
% 	\begin{center}
% 		\includegraphics[scale = 0.5]{img/soundFileToRam2.png}
% 		\caption{sound in Ram}
% 		\label{fig:soundRam}
% 	\end{center}
% \end{figure}

\begin{figure}[H]
	\begin{center}
		\includegraphics{img/RamFilePlayback.png}
		\caption{Audio file playback from RAM.}
		\label{fig:RamFilePlayback}
	\end{center}
\end{figure}

\begin{figure}[H]
	\begin{center}
		\includegraphics{writingAudio.png}
		\caption{writing Audio to disk}
		\label{fig:writing}
	\end{center}
\end{figure}

\bgInfo{
\subsection{Granular Sampling}
In figure \ref{fig:granular} you see the basic structure of granular sampling. Granular sampling allows us for example to playback a file slower without lowering the pitch. It is one of the methods to make speed and ppitch independent from each other during playback. Other methods also include FFT based approaches.

\begin{figure}[H]
	\begin{center}
		\includegraphics[width=\textwidth]{img/grain2.png}
		\caption {The patcher \href{./patchers/01\_waveshaping/granular.pd}{\texttt{patchers/01\_waveshaping/granular.pd}}, a simplified version of granular sampling}
		\label{fig:granular}
	\end{center}
\end{figure}
}

\section{Key Points}

\begin{itemize}
	\item When do we sampling from RAM when from disk?
	\item what are the problems with waveshaping?
	\item Make sure you understand that waveshaping can produce overtones.
	\item Make sure if you see a (simple) mathematical expression you can decide if it is non-linear or not.
	\item Make sure you recognize waveshaping in Max if you see it (e.g. figure \ref{fig:squarePd} )
\end{itemize}

% \section{Hausübung}
% \subsection{Testmodul}

% baue ein audio Testmodul mit folgener spezifikation:\\
% \begin{itemize}
% 	\item Ein audio output
% 	\item verschiedene klangquellen wählbar:
% 		\begin{enumerate}
% 			\item White Noise
% 			\item Sinus (freq. einstellbar)
% 			\item soundfile (file wählbar)
% 		\end{enumerate}
% 	\item GUI
% 	\item verfügbar(in eurem pfad, und jederzeit abrufbar als abstraction)
% 	\item output pegel sichtbar (level meter)
% \end{itemize}

% \begin{figure}[H]
% 	\begin{center}
% 		\includegraphics[scale = 1]{img/audioTester.png}
% 		\caption{audioTester.pd, zu bauen als Hausübung}
% 		\label{fig:audiotester}
% 	\end{center}
% \end{figure}


\chapter{Introduction}\label{Chap:Intro}
Magnetohydrodynamic turbulence offers a rich variety of physical
phenomena and hence is still a field of intense research.  In
comparison to pure (incompressible) hydrodynamical turbulence, the
presence of magnetic fields introduces additional complexity to the
problem, changing the picture from the classical turbulence theory
introduced by Kolmogorov \citep{Kolmogorov41}.

Hence, MHD turbulence has long been an area of interest.
For example, a large scale background field or the field on the
largest eddy-containing scales could give rise to modifications of the
small-scale fluctuations compared to pure hydrodynamic turbulence.
Iroshnikov \cite{Iroshnikov1964} \& Kraichnan
\cite{Kraichnan1965b} firstly introduced a modified theoretical
description where only waves of opposite directions interact.
This interaction is then governed by the \alfven timescale
$\tau_A\sim l/v_A$ which is shorter than the eddy-distortion time
$\tau_l$ considered otherwise.  This introduces an additional factor
of $\tau_l/\tau_A$ in the energy-transfer time which is used in the
derivation of the hydrodynamic turbulence theory.  The \alfven effect
\citep{Iroshnikov1964,Kraichnan1965b} causes the inertial-range
scaling to differ from classical HD turbulence, effectively leading to
a more shallow spectrum of $E\sim k^{-3/2}$, rather than $E\sim k^{-5/3}$.

The theory of \alfvenic wave interaction was extended by Sridhar \&
Goldreich and Goldreich \& Sridhar
\citep{SridharGoldreich94, SridharGoldreich95} to include interactions
of multiple \alfvenic wave modes.  It then follows that 3-mode wave
interactions do not give rise to resonances which then leads to the
conclusion of a failure of the IK theory. \hl{A first complete discussion of MHD
turbulence with resonant interactions was discussed by Galtier et. al (2000)} \cite{Galtier2000}.

The detailed analysis of MHD turbulence including resonant 4-wave
interactions gives rise to a steeper spectrum of
$E_k\propto k_{\|}^{-2}$, but also a highly anisotropic spectrum where
one has to differentiate between the perpendicular and the parallel
parts of the energy spectrum.  Cho \& Vishniac
\cite{ChoVishniac2000} and more recently also Beresnyak
\cite{Beresnyak15} conclude in their analysis that a theoretically
derived Sridhar \& Goldreich spectrum agrees with their numerical
simulations.  See the book by Biskamp \cite{BiskampBook} for a
a more detailed discussion about the effects of \alfvenic waves in
turbulent fields.

Another important phenomenon is observed when the field exhibits
\textit{magnetic helicity}. In this case it is well known that the
decay is drastically different where one observes an increase of
magnetic energy on large scales and hence, a dynamical growth of the
correlation length (see e.g. Pouquet et al., Christensson et
al., \cite{Pouquet1976,Christensson01}). This effect of an
\textit{inverse cascade} is due to the well conserved helicity during
the turbulent decay (see also \cref{Sec:hel_decay} in this work).

Without the presence of helicity, earlier studies by Batchelor \citep{Batchelor50},
Saffman \citep{Saffman67},  Banerjee \& Jedamzik \citep{Banerjee04} and Sethi et al. \citep{Sethi05} showed that for blue magnetic field spectra, \hl{i.e. a spectrum which rises for large Fourier modes}, the coherence length also increases but this happens
by the damping of small-scale fluctuations, leaving only large-scale fluctuations.
In this case, the decay law for the magnetic energy and the growth rate of the coherence length
depends on the large scale spectral index of the magnetic field
fluctuations.
Also, other numerical studies confirmed that
the peak of the magnetic spectrum moves along the large scale spectrum
while the small-scale fluctuations decay
(e.g. \cite{Campanelli07,Saveliev12,Saveliev13}).

Recently, Brandenburg et al. \cite{Brandenburg15} suggested
that, even without helicity, the magnetic energy can increase on scales
larger than the initial integral scale, and the coherence length can
moderately grow through an effect similar to the helical case.
But this nonhelical \textit{inverse transfer} requires high Reynolds
numbers. Hence, previous studies of nonhelical MHD turbulence decay
have not seen this effect clearly \citep{MuellerBiskamp99,
  Christensson01, Banerjee04b, Kalelkar04} whereas latest numerical studies seem
to confirm the result by Brandenburg et al.
\cite{Zrake2014,Linkmann16}.

If the effect of the inverse transfer is proven to be universal for
large Reynolds number regimes, it would have a large impact for
magnetic field evolution, in particular, during the Early
Universe. Here, slight changes of the turbulent decay law (which is
typically a power law of the time $t$) will result in different field
strengths and coherence lengths at later epochs. For instance,
assuming a magneto-genesis scenario during the electroweak (EW) phase
transition, Wagstaff et al. \cite{Wagstaff16} \hl{showed that the
decay of the magnetic field will be too fast to explain the weak lower bounds
of the magnetic fields in the voids of galaxies as inferred from Fermi
observations of TeV Blazars} \cite{Neronov10, Taylor11}. Without the
effect of the inverse transfer the magnetic energy will decay as
$E_B \propto t^{-10/7}$ (see e.g. \cite{Banerjee04b, Sethi05}) if a
causal magnetic field spectrum with no helicity is assumed
\cite{Durrer03}. Otherwise, according to the decay law by the effect
of the inverse transfer, the magnetic energy decays as $E_B \propto
t^{-1}$, leaving strong enough present-day magnetic fields to explain
the fields in voids of galaxies \cite{Kahniashvili13}.

Motivated by the work by Brandenburg et. al (2015) \cite{Brandenburg15},
we performed a detailed numerical investigation to test the regimes where one can
expect an efficient inverse transfer of energy to larger scales during
the decay of magnetic fields.
Unlike in the case of helical magnetic fields, where helicity is a
conserved quantity and energy is transferred to larger scales by an
inverse cascade, the physical reasoning of the non-helical
\textit{inverse transfer} is not understood (see appendix of this work
and supplement of \cite{Brandenburg15}). Our goal is to shed some light on
this phenomenon. For this reason, we mainly use the well established
Pencil Code \cite{PENCIL10}, which was also used in the original study
by Brandenburg et al. \cite{Brandenburg15}, where we vary the
Reynolds number, the Prandtl number as well as the initial spectra of
the stochastic magnetic field.

This work starts off with a discussion of helical and nonhelical
turbulence in \cref{Chap:Turbulence}.  In \cref{Chap:Methods} we
describe the details of our numerical setup, the analysis methods and
the run-time parameters. We then present the simulation results in
\cref{Chap:Results} where we discuss the impact of the variation of
the viscosity parameter and the Prandtl number as well as the
influence of the initial spectrum on the \textit{inverse transfer}.
Furthermore, we present a run with the \textit{Zeus-MP2} Code, where
we don't see enough evidence for the \textit{inverse transfer} and
discuss how that could be linked to the numerical integration
scheme. We conclude in \cref{Chap:Conc} with the discussion
of our main findings and their impact on causally generated fields in
the early Universe questioning the effect of the inverse transfer due
to large expected Prandtl numbers.
% \begin{itemize}
%     \item What is the subject of the study? Describe the
%         economic/econometric problem.
%
%     \item What is the purpose of the study (working hypothesis)?
%
%     \item What do we already know about the subject (literature
%         review)? Use citations: \textit {\citet{Gallant:87} shows that...
%         Alternative Forms of the Wald test are considered
%         \citep{Breusch&Schmidt:88}.}
%
%     \item What is the innovation of the study?
%
%     \item Provide an overview of your results.
%
%
%     \item Outline of the paper:\\
%         \textit{ The paper is organized as follows. The next section describes the
%         model under investigation. Section \ref{Sec:Data} describes the data set
%         and Section \ref{Sec:Results} presents the results. Finally, Section
%         \ref{Sec:Conc} concludes.}
%
%     \item The introduction should not be longer than 4 pages.
%
%\end{itemize}


% EDIT HERE
% Enter team number below ??
\newcommand{\TeamNo}{31}
% Enter HW number below ??
\newcommand{\HWno}{01}
% 1st student information
\newcommand{\AuthorOneName}{Merve Nur Öztürk}
\newcommand{\AuthorOneID}{2311322}
% 2nd student information (leave empty if none)
\newcommand{\AuthorTwoName}{Atakan Süslü}
\newcommand{\AuthorTwoID}{2311371}
% 3rd student information (leavIDnumber1e empty if none)
\newcommand{\AuthorThreeName}{Betül Rana Kuran}
\newcommand{\AuthorThreeID}{2311173}
% END EDITING
% DO NOT MODIFY BELOW EXCEPT FOR ADDING PACKAGES #######
\documentclass[letterpaper,12pt]{article}
\usepackage{tabularx} % extra features for tabular environment
\usepackage{amsmath}  % improve math presentation
\usepackage{amssymb}
\usepackage{xcolor}
\usepackage{float}
\usepackage[export]{adjustbox}
\usepackage{graphicx} % takes care of graphic including machinery
\usepackage[margin=1in,letterpaper]{geometry} % decreases margins
\usepackage{cite} % takes care of citations

\begin{document}
\begin{center}
AE 305, 2020-21 Fall \hfill \textbf{HW \HWno} \hfill \textbf{Team \TeamNo} \\
\noindent\rule{\textwidth}{0.4pt}
\begin{tabular}{p{0.33\textwidth} | p{0.33\textwidth} | p{0.33\textwidth} }
	\AuthorOneName&\AuthorTwoName&\AuthorThreeName\\
	\textit{\AuthorOneID}&\textit{\AuthorTwoID}&\textit{\AuthorThreeID}
\end{tabular}
\noindent\rule{\textwidth}{0.4pt}
\end{center}

%Report start

\section{Introduction}

It is practical to use numerical methods in order to solve differential equations when
the analytical solution is time-consuming or an analytical solution does not exist, which was
the case for our homework problem. In this homework, we are given an aircraft
which rolls on the ground and takes off some time later, and we are asked to find
the minimum time required for this aircraft to take off at different airport altitudes.
We know that the aircraft will take off when the lift force is greater than the weight of
the aircraft. Since the lift force is a function of velocity;

\begin{equation}
        L = C_L \cdot \frac{1}{2} \cdot \rho_{\infty} \cdot V_{\infty}^{2} \cdot S
\end{equation}

where the lift coefficient $C_L$ is assumed to be constant and equal to the maximum lift coefficient
($C_{L,max} = 1.792$), first, we should calculate velocity which is described in a differential form for
this problem using the force balance equation in the horizontal direction:

\begin{equation}
        \frac{W}{g} \cdot \frac{dV}{dt} = T - D - \mu \cdot (W - L)
\end{equation}

where the lift and drag forces are initially zero. The next values of drag force are calculated
by this formula:

\begin{equation}
        D = C_D \cdot \frac{1}{2} \cdot \rho_{\infty} \cdot V_{\infty}^{2} \cdot S
\end{equation}

The drag coefficient $C_D$ is also assumed to be constant ($C_D = 0.215$) and its value is
calculated by this equation;

\begin{equation}
        C_D = 0.0207 + 0.0605C_L^{2}
\end{equation}

Therefore, we are asked to use Euler's and RK2 methods so that we can approach the
solution with the help of numerical methods.

\section{Method}
Euler's method can be defined as the first-order Taylor Series Expansion. In this method, the space between
the initial point of the independent variable and the desired next point is divided into discrete points. The
difference between respective discrete points is named as step size, $\Delta x$. Then, a first-order ordinary
differential equation at the initial point is calculated and treated as slope.
\begin{equation}
\frac{dy}{dx} \equiv y \prime \equiv f(x,y) \equiv SLOPE
\end{equation}
The slope is multiplied by the stepsize
and added to the initial value of the dependent variable. The result gives the next value of the dependent variable.

\begin{center}
Next Value = Previous Value + Step Size $\times $ Slope
\end{center}
\begin{equation}
y(x + \Delta x ) = y(x) + \Delta x f(x,y)
\end{equation}
\begin{equation}
y_{i+1} = y_i + \Delta x f(x_i , y_i)
\label{eq:eul}
\end{equation}
This equation is repeated until the $x_i$ exceeds the desired independent point.

Second-Order Runge-Kutta method has a similar equation form with Euler's method:
\begin{equation}
y_{i+1} = y_i + \Delta x \phi (x_i , y_i, \Delta x)
\label{eq:rk2}
\end{equation}
However, in second order RK method, instead of $y\prime $, $\phi$, which is
called the increment function, is used. $\phi$ is weighted slope function over the interval.
\begin{eqnarray}
\phi&=&a_1k_1 + a_2k_2\\
\frac{dy}{dx}&=&f(x,y) \nonumber\\
k_1&=&f(x_i,y_i) \nonumber\\
k_2&=&f(x_i+p_i\Delta x, y_i+p_i\Delta x k_1) \nonumber
\end{eqnarray}
where $p_i<1$.
From the second-order Taylor Series expansion about $(x_i,y_i)$, two equations are determined:
\begin{eqnarray}
a_1+a_2 = 1  \nonumber \\
a_2p_1 = \frac{1}{2} \nonumber
\end{eqnarray}
We chose $p_i = 2/3 $. Therefore, we found $a_1=1/4$ and $a_2=3/4$ as our weights.
\\\\
Trapezoidal integration rule is a basic version of calculating the area under a curve. It is based on
dividing the area under the curve $y(x)$ into small trapezoids. Then, areas of trapezoids which is equal to
$\frac {1}{2}(V_i+V_{i+1})\Delta t $ is summed up:
\begin{equation}
\int_{0}^{N_p\Delta t} V(t) dt = \sum_{i=0}^{N_p-1} \frac{1}{2}(V_i+V_{i+1}) \Delta t
\end{equation}

\newpage

\section{Results and Discussion}

\subsection{Calculation of velocity at sea level with Euler's Method }
\begin{figure}[ht]
\centering \includegraphics[max height=10cm]{graphs/question1.eps}
\caption{Calculated velocities at sea level using Euler's Method with three different step sizes.}
     \label{fig:q1}
\end{figure}

As can be seen in Figure \ref{fig:q1}, by using different time step sizes, we obtain different results.
Initially, the results were approximately the same for all time step sizes, but as time progresses, the margin of error increases.
This increase occurs at different rates for each time step size. In order to illustrate, when $ \Delta t = 3 $, the
error grows faster than other cases. If we assume that we have the least error when $ \Delta t = 0.5 $, since it is
the smallest step size among all, we can observe that the curves of the other step sizes deviate more as the time step size gets
higher. Thus, when $ \Delta t = 3 $, the result is the least accurate.

\newpage
\begin{figure}[ht]
        \centering \includegraphics[max height=10cm]{graphs/question1_finaltime.eps}
        \caption{Detailed version of Figure \ref{fig:q1} focused on the endpoints.}
        \label{fig:q1_closer}
\end{figure}

 The effects of using different time step sizes on the result can be clearly seen in Figure \ref{fig:q1_closer}.
 In the first problem of the homework, we were asked to find the minimum time needed for the given aircraft to
 lift off at sea level. When we take a closer look at the curves as we did in Figure \ref{fig:q1_closer}, the
 endpoints, which gives the lift-off time and velocity, are different from each other, and as we mentioned
 before, we approach the result more precisely for $ \Delta t = 0.5 $. That means if we want to obtain a more precise result,
 we must decrease the step size.
\newpage
\subsection{Calculation of velocity at different altitudes with Euler's Method }
\begin{figure}[ht]
        \centering \includegraphics[max height=10cm]{graphs/altitude.eps}
        \caption{Calculated velocities at different altitudes using Euler's method with $\Delta t = 0.5$.}
        \label{fig:altitude}
\end{figure}

It can be obtained from Figure \ref{fig:altitude} that it takes longer for the given aircraft to take off at higher altitudes.
This is because as the altitude gets higher, the air density decreases, which results in lower maximum available
thrust ($ T_{A,max} = T_{A,max,SL} \frac{\rho_{\infty}}{\rho_{\infty,SL}} $). In addition to that,
lift and drag forces also decrease since they are functions of the free stream air density. The decrease in drag should
generally result in shorter take-off time while the decrease in thrust and lift force acts exactly the opposite way. However,
the effect of both the lift force and the thrust overcomes the effect of the drag force. Therefore, take off time increases at higher altitudes.
\newpage
\subsection{Calculation of velocity at sea level with second order RK Method }
\begin{figure}[ht]
        \centering \includegraphics[max height=10cm]{graphs/RK2.eps}
        \caption{Calculated velocities at sea level using second order RK method with different step sizes.}
        \label{fig:rk2}
\end{figure}
The results in Figure \ref{fig:rk2} are more similar to each other than Figure \ref{fig:q1}. This is because RK2 method with $p_i=2/3$
is more accurate than Euler's method. In RK2 method with $p_i=2/3$, average slopes at $t_i$ and $t_{i+p_i\Delta t}$
are used instead of using only one slope at $ t_i $ in every iteration. This leads to more stable results than Euler's method
even with a larger step size. In our case, error became significant only at the endpoints. That error has occured because
algorithm jumps to the next time step even if the true result is closer to the current evaluation point than the next evaluation point.
To decrease this error at the endpoints, a smaller time step must be used.
\newpage
\subsection{Comparison of Euler's method and RK2 method at sea level with different step sizes}
\begin{figure}[ht]
        \centering \includegraphics[max height=10cm]{graphs/compare05.eps}
        \caption{Calculated velocities at sea level using second order RK method and Euler's method for $\Delta t=0.5$.}
        \label{fig:rk2_05}
\end{figure}
As can be seen from the Figure \ref{fig:rk2_05}, for $\Delta t = 0.5$, results of RK2 method with $p_i=2/3$ and Euler's method
are approximately the same. This is not surprising since the time step size is so small that the margin of error does not change
significantly for different numerical methods, and we gain accurate results for both methods.
\newpage
\begin{figure}[!h]
        \centering
        \includegraphics[max height=8cm]{graphs/compare1.eps}
        \caption{Calculated velocities at sea level using second order RK method and Euler's method for $\Delta t=1$.}
        \label{fig:rk2_1}

        \includegraphics[max height=8cm]{graphs/compare3.eps}
        \caption{Calculated velocities at sea level using second order RK method and Euler's method for $\Delta t=3$.}
        \label{fig:rk2_3}
\end{figure}
The Figures \ref{fig:rk2_1} and \ref{fig:rk2_3} show that increasing step size caused the increase in the
difference between the results of Euler's method and RK2. This is another proof of larger step sizes leads to an increase in error.
The RK2 method has less truncation error than the Euler's method; therefore, it is more accurate than Euler's method with bigger
time steps.

\newpage
\subsection{Calculation of ground roll distance at different altitudes}

\begin{table}[!h]
        \begin{center}
        \caption{Take-off distance $x$ for different altitudes.}
        \vspace{1em}
        \label{tbl:takeoff}
        \begin{tabular}{|c|c|}
        \hline
        \multicolumn{1}{|c|}{\bf{Altitude (m)}} & \multicolumn{1}{c|}{\bf{\textit{x} (m)}} \\
        \hline
        0 &   493.686 \\ \hline
        1000 &   607.273 \\ \hline
        2000 &   772.654 \\ \hline
        \end{tabular}
        \end{center}
\end{table}

First, velocities were calculated using RK2 Method with $\Delta t = 0.5$, which is the smallest
timestep used in this problem. Then, integral was taken for each interval using Trapezoidal Integration Rule.

As can be seen in Table \ref{tbl:takeoff}, at higher altitudes, take off distance increases dramatically.

\section{Conclusion}
We have calculated the minimum take-off time using Euler's Method and second-order RK Method at different altitudes.
We used different time steps for each method and compared the effect of different time step sizes.

Our computations demonstrated that second-order RK Method gives more reliable results than Euler's Method
when computed with bigger step sizes. We observed that using smaller time step sizes minimizes the effect of truncation error
caused by the usage of different numerical methods. Therefore, if small time step sizes are used, there is no
significant difference between these two numerical methods.

Also, we have shown that at higher altitudes, both minimum take-off time and ground roll distance are longer.
That is because airplane has to reach a higher velocity to take off.
\end{document}


\chapter{Magnetic Fields and Magnetized Turbulence}
\label{ch:magnetic}

\marginnote{
\textbf{Suggested background reading:}
\begin{itemize}
\item \href{http://adsabs.harvard.edu/abs/2012ARA\%26A..50...29C}{Crutcher, R.~M. 2012, ARA\&A, 50, 29} \nocite{crutcher12a}
\end{itemize}
\textbf{Suggested literature:}
\begin{itemize}
\item \href{http://adsabs.harvard.edu/abs/2008ApJ...684..380L}{Li, P.~S., McKee, C.~F., Klein, R.~I., \& Fisher, R.~T. 2008, ApJ, 684, 380} \nocite{li08a}
\end{itemize}
}

In our treatment of fluid flow and turbulence in Chapter \ref{ch:turbulence}, we concentrated on the hydrodynamic case. However, real star-forming clouds are highly magnetized. We therefore devote this chapter to the question of how magnetic fields change the nature of molecular cloud fluid flow.

\section{Observing Magnetic Fields}

\subsection{Zeeman Measurements}

We begin by reviewing the observational evidence for the existence and strength of magnetic fields in interstellar clouds. There are several methods that can be used to measure magnetic fields, but the most direct is the Zeeman effect. The Zeeman effect is a slight shift in the energy levels of an atom or molecule in the presence of a magnetic field. Ordinarily the energies of a level depend only the direction of the electron spin relative to its orbital angular momentum vector, not on the direction of the net angular momentum vector. However, in the presence of an external magnetic field, states with different orientations of the net angular momentum vector of the atom have slightly different energies due to the interaction of the electron magnetic moment with the external field. This causes levels that are normally degenerate to split apart slightly in energy. As a result, transitions into or out of these levels, which would normally produce a single spectral line, instead produce a series of separate lines at slightly different frequencies.

For the molecules with which we are concerned, the level is normally split into three sublevels -- one at slightly higher frequency than the unperturbed line, one at slightly lower frequency, and one at the same frequency. The strength of this splitting varies depending on the electronic configuration of the atom or molecule in question. For OH, for example, the splitting is $Z=0.98$ Hz/$\mu$G, where the parameter $Z$ is called the Zeeman sensitivity, and the shift is $\Delta \nu = BZ$, where $B$ is the magnetic field strength. Zeeman measurements target molecules where $Z$ is as large as possible, and these are generally molecules or atoms that have an unpaired electron in their outer shell. Examples include atomic hydrogen, OH, CN, CH, CCS, SO, and O$_2$.

\begin{marginfigure}
\includegraphics[width=\linewidth]{zeeman_crutcher}
\caption[Sample Zeeman detection of a magnetic field]{
\label{fig:zeeman}
Sample Zeeman detection of an interstellar magnetic field using the CN line in the region DR21(OH). The top panel shows the observed total intensity (Stokes $I$, red lines), which is well-fit by two different velocity components (blue lines). The CN molecule has 7 hyperfine components, of which 4 have a large Zeeman splitting and 3 have a small splitting. The middle panel shows the measured Stokes $V$ (circularly polarized emission) for the sum of the 4 strong splitting components, while the bottom panel shows the corresponding measurement for the 3 weak components. The smooth lines show the best fit, with the line of sight magnetic field as the fitting parameter. Credit: \citet{crutcher99b}, \copyright AAS. Reproduced with permission.
}
\end{marginfigure}
Zeeman splitting is not trivial to to measure due to Doppler broadening. To see why, consider the example of OH. The Doppler width of a line is $\sigma_{\nu} = \nu_0 (\sigma_v/c)$, where for the OH transition that is normally used for Zeeman measurements $\nu_0=1.667$ GHz. If the OH molecule has a velocity dispersion of order $0.1$ km s$^{-1}$, as expected even for the lowest observed velocity dispersions found on small scales in molecular clouds, then $(\sigma_v/c)\sim 10^{-6}$, so $\sigma_{\nu} \sim 1$ kHz. This means that, unless the field is considerably larger than $1000$ $\mu$G (1 mG), which it usually is not, the Zeeman splitting is smaller than the Doppler line width. Thus the split lines are highly blended, and cannot be seen directly in the spectrum.

However, there is a trick to avoid this problem: radiation from the different Zeeman sublevels has different polarization. If the magnetic field is along the direction of propagation of the radiation, emission from the higher frequency Zeeman sublevel is right circularly polarized, while radiation from the lower frequency level is left circularly polarized. The unperturbed level is unpolarized. Thus although one cannot see the line split if one looks at total intensity (as measured by the Stokes $I$ parameter), one can see that the different polarization components peak at slightly different frequencies, so that the circularly polarized spectrum (as measured by the Stokes $V$ parameter) looks different than the total intensity spectrum. One can deduce the magnetic field strength along the line of sight from the difference between the total and polarized signals. Figure \ref{fig:zeeman} shows a sample detection.

Applying this technique to line emission from molecular clouds indicates that they are threaded by magnetic fields whose strengths range from tens to thousands of $\mu$G, with higher density gas generally showing stronger fields. We can attempt to determine if this is dynamically important by a simple energy argument. For a low-density envelope of a GMC with $n\sim 100$ cm$^{-3}$ ($\rho \sim 10^{-22}$ g cm$^{-3}$), we might have $v$ of a few km s$^{-1}$, giving a kinetic energy density
\begin{equation}
e_K  = \frac{1}{2}\rho v^2 \sim 10^{-11}\mbox{ erg cm}^{-3}.
\end{equation}
For the magnetic field of $20$ $\mu$G, typical of molecular clouds on large scales, the energy density is
\begin{equation}
e_B = \frac{B^2}{8\pi} \sim 10^{-11} \mbox{ erg cm}^{-3}.
\end{equation}
Thus the magnetic energy density is comparable to the kinetic energy density, and is dynamically significant in the flow.

\subsection{The Chandrasekhar-Fermi Method}

While the Zeeman effect provides by far the most direct method of measuring magnetic field strengths, it is not the only method for making this measurement. Another commonly-used technique, which we will not discuss in any detail, is the Chandrasekhar-Fermi method \citep{chandrasekhar53a}. This method relies on the fact that interstellar dust grains are non-spherical, which has two important implications. First, a non-spherical grain acts like an antenna, in that it interacts differently with electromagnetic waves that are oriented parallel and perpendicular to its long axis. As a result, grains both absorb and emit light preferentially along their long axis. This would not matter if the orientations of grains in the interstellar medium were random. However, there is a second effect. Most grains are charged, and as a result they tend to become preferentially aligned with the local magnetic field. The combination of these two effects means that the dust in a particular region of the ISM characterized by a particular large scale magnetic field will produce a net linear polarization in both the light it emits and any light passing through it. The direction of the polarization then reveals the orientation of the magnetic field on the plane of the sky.

By itself this effect tells us nothing about the strength of the field -- in principle there should be some relationship between field strength and degree of dust polarization, but there are enough other compounding factors and uncertainties that we cannot with any confidence translate the observed degree of polarization into a field strength. However, if we have measurements of the field orientation as a function of position, then we can estimate the field strength from the morphology of the field. As we shall see below, the degree to which field lines are straight or bent is strongly correlated with the ratio of magnetic energy density to turbulent energy density, and so the degree of alignment becomes a diagnostic of this ratio. In fact, one can even attempt to make quantitative field strength estimates from this method, albeit with very large uncertainties.

\section{Equations and Characteristic Numbers for Magnetized Turbulence}

Now that we know that magnetic fields are present, we now turn to some basic theory for magnetized flow. To understand how magnetic fields affect the flows in molecular clouds, it is helpful to write down the fundamental evolution equation for the magnetic field in a plasma, known as the induction equation\footnote{One may find a derivation of this result in many sources. The notation we use here is taken from \citet{shu92a}.}
\begin{equation}
\label{eq:induction}
\frac{\partial \vecB}{\partial t} + \nabla \times (\vecB \times \vecv) = -\nabla \times (\eta \nabla \times \vecB)
\end{equation}
Here $\vecB$ is the magnetic field, $\vecv$ is the fluid velocity (understood to be the velocity of the ions, which carry all the mass, a distinction that will become important below), and $\eta$ is the electrical resistivity. If the resistivity is constant in space, we can use the fact that $\nabla \cdot \vecB=0$ to simplify this slightly to get
\begin{equation}
\label{eq:induction_eta}
\frac{\partial \vecB}{\partial t} + \nabla \times (\vecB \times \vecv) = \eta \nabla^2 \vecB.
\end{equation}
The last term here looks very much like the $\nu\nabla^2 \vecv$ term we had in the equation for conservation of momentum (equation \ref{eq:momentum}) to describe viscosity. That term described diffusion of momentum, while the one in this equation describes diffusion of the magnetic field.\footnote{We are simplifying quite a bit here. The real dissipation mechanism in molecular clouds is not simple resistivity, it is something more complex called ion-neutral drift, which is discussed in Section \ref{sec:non-ideal-mhd}. However, the qualitative analysis given in this section is unchanged by this complexity, and the algebra is significantly easier if we use a simple scalar resistivity.}

We can understand the implications of this equation using dimensional analysis much as we did for the momentum equation in Section \ref{ssec:reynolds_mach}. As we did there, we let $L$ be the characteristic size of the system and $V$ be the characteristic velocity, so $L/V$ is the characteristic timescale. Spatial derivatives have the scaling $1/L$, and time derivatives have the scaling $V/L$. We let $B$ be the characteristic magnetic field strength. Applying these scalings to equation (\ref{eq:induction_eta}), the various terms scale as
\begin{eqnarray}
\frac{BV}{L} + \frac{BV}{L} & \sim & \eta \frac{B}{L^2} \\
1 & \sim & \frac{\eta}{VL}
\end{eqnarray}
In analogy to the ordinary hydrodynamic Reynolds number, we define the magnetic Reynolds number by
\begin{equation}
\mbox{Rm} = \frac{LV}{\eta}.
\end{equation}
Magnetic diffusion is significant only if $\mathrm{Rm} \sim 1$ or smaller.

What is Rm for a typical molecular cloud? As in the hydrodynamic case, we can take $L$ to be a few tens of pc and $V$ to be a few km s$^{-1}$. The magnetic field $B$ is a few tens of $\mu$G. The electrical resistivity is a microphysical property of the plasma, which, for a weakly ionized plasma, depends on the ionization fraction in the gas and the ion-neutral collision rate. We will show in Section \ref{sec:non-ideal-mhd} that a typical value of the resistivity\footnote{Again keeping in mind that this is not a true resistivity, it is an order of magnitude effective resistivity associated with ion-neutral drift.} in molecular clouds is $\eta\sim 10^{22}-10^{23}$ cm$^2$ s$^{-1}$. If we consider a length scale $L\sim 10$ pc and a velocity scale $V\sim 3$ km s$^{-1}$, then $LV\sim 10^{25}$ cm$^2$ s$^{-1}$, then this implies that the Rm for molecular clouds is hundreds to thousands.

Again in analogy to hydrodynamics, this means that on large scales magnetic diffusion is unimportant for molecular clouds -- although it is important on smaller scales. The significance of a large value of Rm becomes clear if we write down the induction equation with $\eta=0$ exactly:
\begin{equation}
\frac{\partial \vecB}{\partial t} + \nabla \times (\vecB \times \vecv) = 0.
\end{equation}
To understand what this equation implies, it is useful consider the magnetic flux $\Phi$ threading some fluid element. We define this as
\begin{equation}
\Phi = \int_A  \vecB \cdot \nhat\, dA,
\end{equation}
where we integrate over some area $A$ that defines the fluid element. The time derivative of this is then
\begin{eqnarray}
\frac{d\Phi}{dt} & = & \int_A \frac{\partial\vecB}{\partial t}\cdot\nhat\, dA + \oint_{\partial A} \vecB\cdot \vecv \times d\mathbf{l} \\
& = & \int_A \frac{\partial\vecB}{\partial t}\cdot\nhat\, dA + \oint_{\partial A} \vecB\times \vecv \cdot d\mathbf{l}
\end{eqnarray}
where $\partial A$ is the boundary of $A$. Here the second term on the right comes from the fact that, if the fluid is moving at velocity $\vecv$, the area swept out by a vector $d\mathbf{l}$ per unit time is $\vecv\times d\mathbf{l}$, so the flux crossing this area is $\vecB\cdot \vecv\times d\mathbf{l}$. Then in the second step we used the fact that $\nabla\cdot \vecB = 0$ to exchange the dot and cross products.

If we now apply Stokes theorem again to the second term, we get
\begin{eqnarray}
\frac{d\Phi}{dt}
& = & \int_A \frac{\partial\vecB}{\partial t}\cdot\nhat\, dA + \int_A \nabla\times (\vecB\times \vecv) \cdot \nhat\, dA \\
& = & \int_A \left[\frac{\partial\vecB}{\partial t} + \nabla\times (\vecB\times \vecv)\right]\cdot\nhat\,dA\\
& = & 0.
\end{eqnarray}
The meaning of this is that, when Rm is large, the magnetic flux through each fluid element is conserved. This is called flux-freezing, since we can envision it geometrically as saying that magnetic field lines are frozen into the fluid, and move along with it. Thus on large scales the magnetic field moves with the fluid. However, on smaller scales the magnetic Reynolds number is $\sim 1$, and the field lines are not tied to the gas. We will calculate this scale in Section \ref{sec:non-ideal-mhd}. Before doing so, however, it is helpful to calculate another important dimensionless number describing the MHD flows in molecular clouds.

The conservation of momentum equation including magnetic forces is
\begin{equation}
\frac{\partial}{\partial t}(\rho \mathbf{v}) = -\nabla \cdot(\rho \mathbf{v v}) - \nabla P + \rho \nu \nabla^2 \mathbf{v} + \frac{1}{4\pi} (\nabla\times\vecB)\times \vecB,
\end{equation}
and if we make order of magnitude estimates of the various terms in this, we have
\begin{eqnarray}
\frac{\rho V^2}{L} & \sim & -\frac{\rho V^2}{L} + \frac{\rho c_s^2}{L} + \frac{\rho \nu V}{L^2} + \frac{B^2}{L} \\
1 & \sim & 1 + \frac{c_s^2}{V^2} + \frac{\nu}{VL} + \frac{B^2}{\rho V^2}
\end{eqnarray}
The second and third terms on the right hand side we have already defined in terms of $\mathcal{M}= V/c_s$ and $\mathrm{Re} = LV/\nu$. We now define our fourth and final characteristic number,
\begin{equation}
\mathcal{M}_A \equiv \frac{V}{v_A},
\end{equation}
where
\begin{equation}
v_A = \frac{B}{\sqrt{4\pi \rho}}
\end{equation}
is the Alfv\'{e}n speed -- the speed of the wave that, in magnetohydrodynamics, plays a role somewhat analogous to the sound wave in hydrodynamics. In flows with $\mathcal{M}_A \gg 1$, which we refer to as super-Alfv\'{e}nic, the magnetic force term is unimportant, while in those with $\mathcal{M}_A \ll 1$, referred to as sub-Alfv\'{e}nic, it is dominant.

For characteristic molecular cloud numbers $n\sim 100$ cm$^{-3}$, $B$ of a few tens of $\mu$G, and $V$ of a few km s$^{-1}$, we see that $v_A$ is of order a few km s$^{-1}$, about the same as the velocity. Thus the flows in molecular clouds are highly supersonic ($\mathcal{M}\gg 1$), but only trans-Alfv\'{e}nic ($\mathcal{M}_A \sim 1$), and magnetic forces have a significant influence. These forces make it much easier for gas to flow along field lines than across them, and result in a pattern of turbulence that is highly anisotropic (Figure \ref{fig:alfvenmach}).

\begin{figure}
\includegraphics[width=\linewidth]{alfvenmach_stone98}
\caption[Comparison of simulations of Alfv\'{e}nic and sub-Alfv\'{e}nic turbulence]{
\label{fig:alfvenmach}
Simulations of sub-Alfv\'{e}nic (left) and Alfv\'{e}nic (right) turbulence. Colors on the cube surface are slices of the logarithm of density, blue lines are magnetic field lines, and red surfaces are isodensity surfaces for a passive contaminant added to the flow. Credit: \citet{stone98a}, \copyright\,AAS. Reproduced with permission.
}
\end{figure}

\section{Non-Ideal Magnetohydrodynamics}
\label{sec:non-ideal-mhd}

We have just shown that the magnetic Reynolds number is a critical parameter for magnetized turbulence, and that this depends on the resistivity $\eta$. In the final part of this Chapter we will discuss in a bit more detail the physical origins of resistivity and related effects.

\subsection{Ion-Neutral Drift}

Molecular clouds are not very good plasmas. Most of the gas in a molecular cloud is neutral, not ionized. The ion fraction may be $10^{-6}$ or lower. Since only ions and electrons can feel the Lorentz force directly, this means that fields only exert forces on most of the particles in a molecular cloud indirectly. The indirect mechanism is that the magnetic field exerts forces on the ions and electrons (and mostly ions matter for this purpose), and these then collide with the neutrals, transmitting the magnetic force.

If the collisional coupling is sufficiently strong, then the gas acts like a perfect plasma. However, when the ion fraction is very low, the coupling is imperfect, and ions and neutrals do not move at exactly the same speed. The field follows the ions, since they are much less resistive, and flux freezing for them is a very good approximation, but the neutrals are able to drift across field lines. This slippage between ions and neutrals is called ion-neutral drift, or ambipolar diffusion.

To estimate how this process works, we need to think about the forces acting on both ions and neutrals. The ions feel a Lorentz force
\begin{equation}
\vecf_L = \frac{1}{4\pi} (\nabla \times \vecB) \times \vecB.
\end{equation}
The other force in play is the drag force due to ion-neutral collisions, which is
\begin{equation}
\vecf_d = \gamma\rho_n \rho_i (\vecv_i-\vecv_n),
\end{equation}
where the subscript $i$ and $n$ refer to ions and neutrals, respectively, and $\gamma$ is the drag coefficient, which can be computed from the microphysics of the plasma. In a very weakly ionized fluid, the neutrals and ions very quickly reach terminal velocity with respect to one another, so the drag force and the Lorentz force must balance. Equating our expressions and solving for $\vecv_d=\vecv_i-\vecv_n$, the drift velocity, we get
\begin{equation}
\vecv_d  = \frac{1}{4\pi\gamma\rho_n\rho_i}(\nabla\times\vecB)\times\vecB
\end{equation}

To figure out how this affects the fluid, we write down the equation of magnetic field evolution under the assumption that the field is perfectly frozen into the ions:
\begin{equation}
\frac{\partial \vecB}{\partial t} + \nabla\times(\vecB\times \vecv_i) = 0.
\end{equation}
To figure out how the field behaves with respect to the neutrals, which constitute most of the mass, we simply use our expression for the drift speed $\vecv_d$ to eliminate $\vecv_i$. With a little algebra, the result is
\begin{equation}
\frac{\partial \vecB}{\partial t} + \nabla\times(\vecB\times \vecv_n) =
\nabla \times \left\{ \frac{\vecB}{4\pi\gamma\rho_n\rho_i}\times\left[\vecB\times(\nabla\times\vecB)\right]\right\}.
\end{equation}
Referring back to the induction equation (\ref{eq:induction}), we can see that the resistivity produced by ion-neutral drift is not a scalar, and that it is non-linear, in the sense that it depends on $\vecB$ itself.

However, our scaling analysis still applies. The magnitude of the resistivity produced by ion-neutral drift is
\begin{equation}
\eta_{\rm AD} = \frac{B^2}{4\pi\rho_i\rho_n\gamma}.
\end{equation}
Thus, the magnetic Reynolds number is
\begin{equation}
\mbox{Rm} = \frac{LV}{\eta_{\rm AD}} = \frac{4\pi L V \rho_i\rho_n\gamma}{B^2} \approx \frac{4\pi L V \rho^2 x\gamma}{B^2},
\end{equation}
where $x=n_i/n_n$ is the ion fraction, which we've assumed is $\ll 1$ in the last step. Ion-neutral drift will allow the magnetic field lines to drift through the fluid on length scales $L$ such that $\mbox{Rm}\lesssim 1$. Thus, we can define a characteristic length scale for ambipolar diffusion by
\begin{equation}
L_{\rm AD} = \frac{B^2}{4\pi\rho^2 x \gamma V}
\end{equation}

In order to evaluate this numerically, we must calculate two things from microphysics: the ion-neutral drag coefficient $\gamma$ and the ionization fraction $x$. For $\gamma$, the dominant effect at low speeds is that ions induce a dipole moment in nearby neutrals, which allows them to undergo a Coulomb interaction. This greatly enhances the cross-section relative to the geometric value. We will not go into details of that calculation, and will simply adopt the results: $\gamma\approx 9.2 \times 10^{13}$ cm$^3$ s$^{-1}$ g$^{-1}$ (\citealt{smith97a}; note that \citealt{shu92a} gives a value that is lower by a factor of $\sim 3$, based on an earlier calculation).

The remaining thing we need to know to compute the drag force is the ion density. In a molecular cloud the gas is almost all neutral, and the high opacity excludes most stellar ionizing radiation. The main source of ions is cosmic rays, which can penetrate the cloud, although nearby strong x-ray sources can also contribute if present. We have already discussed cosmic rays in the context of cloud heating and chemistry, and here too they play a central role. Calculating the ionization fraction requires balancing this against the recombination rate, which is a nasty problem. That is because recombination is dominated by different processes at different densities, and recombinations are usually catalyzed by dust grains rather than occurring in the gas phase. We will not go into the details of these calculations here, and will instead simply quote a rough fit to their results given by \citet{tielens05a},
\begin{equation}
n_i \approx 2\times 10^{-3}\mbox{ cm}^{-3} \left(\frac{n_{\rm H}}{10^4\mbox{ cm}^{-3}}\right)^{1/2} \left(\frac{\zeta}{10^{-16}\mbox{ s}^{-1}}\right)^{1/2},
\end{equation}
where $n_{\rm H}$ is the number density and $\zeta$ is the cosmic ray primary\footnote{I.e., counting only ionizations caused by direct cosmic ray hits, as opposed to ionizations caused when primary electrons go on to ionize additional atoms or molecules.} ionization rate. Thus at a density $n_{\rm H} \sim 100$ cm$^{-3}$, we expect $x\approx 10^{-6}$.

Plugging this into our formulae, along with our characteristic numbers $L$ of a few tens of pc, $V\sim$ a few km s$^{-1}$, and $B\sim 10$ $\mu$G, we find
\begin{eqnarray}
\mbox{Rm} & \approx & 50 \\
L_{\rm AD}& \sim & 0.5\mbox{ pc}.
\end{eqnarray}
If we put in numbers for $L$ and $V$ more appropriate for cores than entire GMCs, we get $L_{\rm AD} \sim 0.05$ pc. Thus we expect the gas to act like a fully ionized gas on scales larger than this, but to switch over to behaving hydrodynamically on small scales.

\subsection{Turbulent Reconnection}

A final non-ideal MHD effect that may be important in molecular clouds, though this is still quite uncertain, is turbulent reconnection. The general idea of reconnection is that, in regions of non-zero resistivity where oppositely directed field lines are brought into close contact, the field lines can break and the field geometry can relax to a lower energy configuration. This may allow the field to slip out of the matter, and it always involves a reduction in magnetic pressure and energy density. The released energy is transformed into heat.

The simplest model of reconnection, the Sweet-Parker model, considers two regions of oppositely-directed field that meet at a plane. On that plane, a large current must flow in order to maintain the oppositely-directed fields on either side of it. Within this sheet reconnection can occur. As with ion-neutral drift, we can define a characteristic Reynolds-like number for this process, in this case called the Lundqvist number:
\begin{equation}
\mathcal{R}_L = \frac{LV}{\eta},
\end{equation}
where here $\eta$ is the true microphysical resistivity, as opposed to the term describing ion-neutral diffusion.

The rate at which reconnection can occur in the Sweet-Parker model is dictated by geometry. Matter is brought into the thin reconnection region, it reconnects, and then it must exit so that new reconnecting matter can be brought in. Matter can only exit the layer at the Alfv\'{e}n speed, and since the cross-section of the reconnection layer is small, this sets severe limits on the rate at which reconnection can occur. It turns out that one can show that the maximum speed at which matter can be brought into the reconnection region is of order $\mathcal{R}_L^{1/2} v_A$.

To figure out this speed, we need to know the resistivity, which is related to the electrical conductivity $\sigma$ by
\begin{equation}
\eta = \frac{c^2}{4\pi \sigma}.
\end{equation}
We will not provide a full calculation of plasma conductivity here\footnote{Again, \citet{shu92a} is a good source for those who wish to see a rigorous derivation.}, but we can sketch the basic outlines of the argument. The conductivity of a plasma is the proportionality constant between the applied electric field and the resulting current,
\begin{equation}
J = \sigma E.
\end{equation}
In a plasma the current is carried by motions of the electrons, which move much faster than the ions due to their lower mass, and the current is simply the electron charge times the electron number density times the mean electron speed: $J = e n_e v_e$. To compute the mean electron speed, one balances the electric force against the drag force exerted by collisions with neutrals (which dominate in a weakly ionized plasma), in precisely the same way we derived the mean ion-neutral drift speed by balancing the drag force against the Lorentz force. Not surprisingly $v_e$ ends up being proportional to $E$, and inversely proportional to the number density of the dominant non-electron species (H$_2$ in molecular clouds) and the cross section of this species for electron collisions. The final result of this procedure is
\begin{equation}
\sigma = \frac{n_e e^2}{m_e n_{\rm H_2} \langle\sigma v\rangle_{e-\rm H_2}} \approx 10^{17} x\mbox{ s}^{-1},
\end{equation}
where $\langle\sigma v\rangle_{e-\rm H_2}\approx 10^{-9}$ cm$^3$ s$^{-1}$ is the mean cross-section times velocity for electron-ion collisions. Plugging this into the resistivity gives
\begin{equation}
\eta \approx \frac{10^3\mbox{ cm}^2\mbox{ s}^{-1}}{x}
\end{equation}
Plugging in our typical value $x\sim 10^{-6}$ gives $\eta\sim 10^{9}$ cm$^2$ s$^{-1}$, and using $L\sim 10$ pc and $V$ of a few km s$^{-1}$, typical molecular cloud numbers, this implies
\begin{equation}
\mathcal{R}_L \sim 10^{16}.
\end{equation}

Of course this makes the reconnection speed truly tiny, of order $10^{-8}$ of $v_A$. So why is reconnection at all interesting? Why is it worth considering? The answer turns on the word turbulent. It turns out that the Sweet-Parker model underpredicts the observed reconnection rate in laboratory experiments or observed in Solar flares and the Earth's magnetosphere. Indeed, if Sweet-Parker were right, there would be no such things as Solar flares.

We currently lack a good understanding of reconnection, but a rough idea is that, in a turbulent medium, reconnection sheets are can be much wider due to turbulent broadening, and that this in turn removes the geometric constraint that makes the reconnection velocity much smaller than the Alfv\'{e}n speed. Exactly how and when this is important in molecular clouds is a subject of very active debate in the literature.