%% Manual / derivations for preconditioning in BOUT++

\documentclass[12pt]{article}
\usepackage[nofoot]{geometry}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage{amsfonts}

\usepackage{listings}
\usepackage{color}
\usepackage{textcomp}
\definecolor{listinggray}{gray}{0.9}
\definecolor{lbcolor}{rgb}{0.95,0.95,0.95}
\lstset{
	backgroundcolor=\color{lbcolor},
        language=C++,
	keywordstyle=\bfseries\ttfamily\color[rgb]{0,0,1},
	identifierstyle=\ttfamily,
	commentstyle=\color[rgb]{0.133,0.545,0.133},
	stringstyle=\ttfamily\color[rgb]{0.627,0.126,0.941},
	showstringspaces=false,
	basicstyle=\small,
	numberstyle=\footnotesize,
	numbers=left,
	stepnumber=1,
	numbersep=10pt,
	tabsize=2,
	breaklines=true,
	prebreak = \raisebox{0ex}[0ex][0ex]{\ensuremath{\hookleftarrow}},
	breakatwhitespace=false,
	aboveskip={1.5\baselineskip},
        columns=fixed,
        upquote=true,
        extendedchars=true,
        morekeywords={Field2D,Field3D,Vector2D,Vector3D,real,FieldGroup},
}

%% Modify margins
\addtolength{\oddsidemargin}{-.25in}
\addtolength{\evensidemargin}{-.25in}
\addtolength{\textwidth}{0.5in}
\addtolength{\textheight}{0.25in}
%% SET HEADERS AND FOOTERS

\pagestyle{fancy}
\fancyfoot{}
\renewcommand{\sectionmark}[1]{         % Lower case Section marker style
  \markright{\thesection.\ #1}}
\fancyhead[LE,RO]{\bfseries\thepage}    % Page number (boldface) in left on even
                                        % pages and right on odd pages 
\renewcommand{\headrulewidth}{0.3pt}

\newcommand{\code}[1]{\texttt{#1}}
\newcommand{\file}[1]{\texttt{\bf #1}}

%% commands for boxes with important notes
\newlength{\notewidth}
\addtolength{\notewidth}{\textwidth}
\addtolength{\notewidth}{-3.\parindent}
\newcommand{\note}[1]{
\fbox{
\begin{minipage}{\notewidth}
{\bf NOTE}: #1
\end{minipage}
}}

\newcommand{\pow}{\ensuremath{\wedge} }

\newcommand{\deriv}[2]{\ensuremath{\frac{\partial #1}{\partial #2}}}
\newcommand{\dderiv}[2]{\ensuremath{\frac{\partial^2 #1}{\partial {#2}^2}}}
\newcommand{\Vec}[1]{\ensuremath{\mathbf{#1}}}
\newcommand{\Div}[1]{\ensuremath{\nabla\cdot #1 }}
\newcommand{\Curl}[1]{\ensuremath{\nabla\times #1 }}
\newcommand{\Bvec}{\ensuremath{\underline{B}}}
\newcommand{\bvec}{\ensuremath{\underline{b}}}
\newcommand{\kvec}{\ensuremath{\underline{\kappa}}}
\newcommand{\apar}{\ensuremath{A_{||}}}

\begin{document}

\title{JOREK-like reduced MHD equations}

\maketitle

\section{Overview}

Implementation of G.Huysmanns' equations used in JOREK for ELM simulations

\section{Starting equations}

From PPCF {\bf 51} (2009) 124012, the {\bf normalised} equations are:
\begin{eqnarray*}
  \deriv{\rho}{t} &=& -\nabla\left(\rho\underline{v}\right) + \nabla\left(D_\perp\nabla_\perp\rho\right) + S_\rho \\
  \rho\deriv{T}{t} &=& -\rho\underline{v}\cdot\nabla T - \left(\gamma - 1\right)\rho T\nabla\cdot\underline{v} + \nabla\cdot\left(\chi_\perp\nabla_\perp T + \chi_{||}\nabla_{||}T\right) + S_T \\
  \underline{e}_\phi\cdot\nabla\times\left(\rho\deriv{\underline{v}}{t}\right) &=& \underline{e}_\phi\cdot\nabla\times\left(-\rho\left(\underline{v}\cdot\nabla\right)\underline{v} - \nabla\left(\rho T\right) + \underline{J}\times\underline{B} + \mu\nabla^2\underline{v}\right) \\
  \underline{B}\cdot\left(\rho\deriv{\underline{v}}{t}\right) &=& \underline{B}\cdot\left(-\rho\left(\underline{v}\cdot\nabla\right)\underline{v} - \nabla\left(\rho T\right) + \underline{J}\times\underline{B} + \mu\nabla^2\underline{v}\right) \\
  \frac{1}{R^2}\deriv{\psi}{t} &=& \eta\left(T\right)\nabla\cdot\left(\frac{1}{R^2}\nabla_\perp\psi\right) - \underline{B}\cdot\nabla \phi
\end{eqnarray*}
where the velocity $\underline{v} = -R\nabla\phi\times\underline{e}_\phi + v_{||}\underline{B}$

\subsection{Normalisation}

The normalisation used in the above equations uses $\mu_0$ and 
a typical mass density $\rho_n$. Here normalised quantities are given hats
(which were omitted in the above equations). Time is normalised as:
\[
\hat{t} = \frac{t}{\sqrt{\mu_0\rho_n}}
\]
and so velocity is normalised to
\[
\hat{v} = v\sqrt{\mu_0\rho_n}
\]

Pressure and current are normalised to $\mu_0$
\[
\hat{p} = \mu_0 p \qquad \hat{j} = \mu_0 j
\]
The normalised pressure here is given by $\hat{p} = \hat{\rho}\hat{T}$.
Since the pressure in Pascals is given by $p = enT$ where $n$ is the number
density and $T$ is in eV, this gives
\[
\frac{1}{\mu_0}\hat{p} = e\frac{\rho_n\hat{\rho}}{m_i} T_0\hat{T}
\]
where $m_i$ is the ion mass. The temperature must therefore be normalised to
\[
T_n = \frac{m_i}{\mu_0 e \rho_n}
\]
which for $n_n=10^{20}$ gives $T_n\simeq 5\times 10^4$.

The diffusion coefficients are normalised to:
\begin{eqnarray*}
\hat{\eta} &=& \eta\sqrt{\rho_n / \mu_0} \\
\hat{\mu} &=& \mu\sqrt{\mu_0/\rho_n} \\
\hat{D_\perp} &=& D_\perp\sqrt{\mu_0\rho_n} \\
\hat{\chi_\perp} &=& \chi_\perp\sqrt{\mu_0/\rho_n}
\end{eqnarray*}
In addition, energy density is normalised as $\hat{\epsilon} = \mu_0\epsilon$ so
power density $w$ (Watts / m$^3$) is normalised as 
$\hat{w} = \mu_0\sqrt{\mu_0\rho_n} w$

For $n_n=10^{20}$m$^{-3}$, these factors are $\sqrt{\rho_n / \mu_0} = 0.52$, $\sqrt{\mu_0/\rho_n}=1.94$ and $\sqrt{\mu_0\rho_n} = 6.48\times 10^{-7}$. 

\section{Equations solved in BOUT++ model}

The total magnetic field is given by:
\[
\Bvec = \Bvec_0 + \nabla\times\left(\bvec_0\apar\right) \simeq \Bvec_0 + \nabla\apar \times\bvec_0
\]
Either of these expressions can be used, depending on the value of the \texttt{full\_bfield} option. The parallel current is given by
\[
j_{||} = j_{||0} - \frac{1}{\mu_0}\nabla_\perp^2\apar
\]
which since $j_{||}$ is normalised to $\mu_0$, and $\apar$ is not normalised gives
\[
\hat{j_{||}} = \hat{j_{||0}} - \nabla_\perp^2\hat{\apar}
\]
The $E\times B$ velocity is given by:
\[
\Vec{v}_{E\times B} = \frac{1}{B^2}\Bvec\times\nabla\phi
\]
Vorticity $U$ is defined as 
\begin{eqnarray*}
U \equiv \Curl{\Vec{v}_{E\times B}} &=& \frac{\bvec}{B}\Div{\nabla\phi} - \nabla\phi\left(\Div{\frac{\bvec}{B}}\right) + \left(\nabla\phi\cdot\nabla\right)\frac{\bvec}{B} - \left(\frac{\bvec}{B}\cdot\nabla\right)\nabla\phi \\
&\simeq& \frac{\bvec}{B}\nabla_\perp^2\phi
\end{eqnarray*}
where only the first term has been kept, and parallel derivatives neglected (flute assumption). Electrostatic potential can therefore be related to 
vorticity by:
\[
U \simeq \frac{1}{B_0}\nabla_\perp^2\phi
\]

The normalised evolution equations solved are:

\begin{eqnarray*}
  \deriv{\rho}{t} &=& -\Vec{v}_{E\times B}\cdot\nabla\left(\rho + \rho_0\right) + \left(\nabla\cdot\Vec{v}_{E\times B}\right)\left(\rho + \rho_0\right) + D_\perp\nabla_\perp^2\rho \\
  \deriv{T_s}{t} &=& -\Vec{v}_{E\times B}\cdot\nabla\left(T_s + T_{s0}\right) - \frac{2}{3}\left(\nabla\cdot\Vec{v}_{E\times B}\right)\left(T_s + T_{s0}\right) \\
  &&+ \frac{1}{\rho + \rho_0}\left[ \nabla_{||}\cdot\left(\chi_{s||}\partial_{||}T_s\right) + \chi_\perp\nabla_\perp^2T_s\right] + \frac{2}{3\left(\rho+\rho_0\right)}W_s \\
  \deriv{U}{t} &=& -\Vec{v}_{E\times B}\cdot\nabla U + \frac{1}{\rho+\rho_0}\left[ B_0^2\nabla_{||}\left(\frac{J_{||}+J_{||0}}{B_0}\right) + 2\bvec_0\times\kvec_0\cdot\nabla P + \nu_{||}\partial_{||}^2u + \nu_\perp\nabla_\perp^2u\right] \\
\deriv{v_{||}}{t} &=& -\Vec{v}_{E\times B}\cdot\nabla v_{||} - \nabla_{||} P \\
\deriv{\apar}{t} &=& -\nabla_{||}\phi - \eta J_{||} \\
P &=& \rho\left(T_e + T_i\right)
\end{eqnarray*}
where there is a separate equation for electron and ion temperatures which
differ only in conductivity coefficients. All quantities with subscript '0'
are (constant) equilibrium quantites, everything else is evolving.

$W_s$ is the rate of exchange between thermal energy and other forms. For
ions this is due to collisions with the electrons. The standard Chapman-Enskog
collisional expression ($T$ in eV, $W$ in Watts/m$^3$) is
\[
W_i = 3\frac{m_e}{m_i}\frac{en}{\tau_e}\left(T_e - T_i\right)
\]
whilst the electron expression is
\[
W_e = -W_i + \eta J_{||}^2
\]
and so the normalised expressions are:
\begin{eqnarray*}
  \hat{W}_i &=& 3\frac{m_e}{m_i} \frac{\hat{\rho}}{\hat{\tau}_e}\left(\hat{T}_e - \hat{T}_i\right) \\
  \hat{W}_e &=& -\hat{W}_i + \hat{\eta}_{||}\hat{J}_{||}^2
\end{eqnarray*}
The Spitzer resistivity is used:
\[
\eta_{||} = \frac{m_e}{1.96ne^2\tau_e} \qquad \Rightarrow \hat{\eta}_{||} = \frac{m_em_i}{1.96\mu_0\rho_ne^2}\frac{1}{\hat{\tau}_e\hat{\rho}}
\]
whilst the electron-ion collision time in seconds is
\[
\tau_e = 3.44\times 10^{11}\frac{T_e^{3/2}}{n}\frac{1}{Z_i\ln\Lambda}
\]
The Coulomb logarithm is only calculated once at the start based on the maximum density and temperature in the domain. Typical values for normalised $\tau_e$ are $10 - 10^3$. Due to the factor of $m_e/m_i$, the $W_i$ term will only become important for long very long simulations. 

Both $W_i$ and $\eta_{||}$ are multiplied by factors read from the input file (\texttt{wei} and \texttt{eta} respectively) to scale up or down relative to these collisional estimates. Set \texttt{wei} $\le 0$ to switch off this term.

\subsection{Divergence of $E\times B$ flow}

\[
\nabla\cdot\Vec{v}_{E\times B} = \nabla\cdot\left(\frac{1}{B_0}\bvec_0\times\nabla\phi\right)
\]

Using $\nabla\cdot\left(\Vec{F}\times\Vec{G}\right) = \left(\nabla\times\Vec{F}\right)\cdot\Vec{G} - \Vec{F}\cdot\left(\nabla\times\Vec{G}\right)$, this becomes
\[
\nabla\cdot\Vec{v}_{E\times B} = \left[\nabla\times\left(\frac{1}{B_0}\bvec_0\right)\right]\cdot\nabla\phi - \frac{1}{B_0}\bvec_0\times\nabla\times\nabla\phi
\]
The second term is identically zero (curl of gradient), and the first term becomes:
\[
\nabla\cdot\Vec{v}_{E\times B} = \left[\nabla\left(\frac{1}{B_0}\right)\times\bvec_0 + \frac{1}{B_0}\nabla\times\bvec_0\right]\cdot\nabla\phi
\]
The second term can be written in terms of the curvature $\kvec_0$ using:
\[
\bvec_0\times\kvec_0 = \bvec\times\left[\left(\nabla\times\bvec\right)\times\bvec\right] = \nabla\times\bvec_0 - \bvec_0\left[\bvec_0\cdot\left(\nabla\times\bvec_0\right)\right]
\]
Hence the divergence of $E\times B$ flow can be written as
\[
\nabla\cdot\Vec{v}_{E\times B} = -\bvec_0\times\nabla\left(\frac{1}{B_0}\right)\cdot\nabla\phi + \frac{1}{B_0}\bvec_0\times\kvec_0\cdot\nabla\phi + \left[\bvec_0\cdot\left(\nabla\times\bvec_0\right)\right]\bvec_0\cdot\nabla\phi
\]
Currently the code includes the first two terms, but drops the last parallel
derivative. This is on the grounds that parallel gradients of $\phi$ should
be small relative to perpendicular gradients (the first two terms).

\end{document}

