<commit_before>%%%%%%%%%%%%%%%%%%%%%definitions%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\input{../../doc/related_pages/header.tex}
\input{../../doc/related_pages/newcommands.tex}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%DOCUMENT%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}

\title{
The full-F electromagnetic model in toroidal geometry \textsc{Feltor}}
\author{ M.~Wiesenberger and M.~Held}
\maketitle

\begin{abstract}
The purpose of this document is to describe the programs
\texttt{feltor\_hpc.cu, feltor.cu, feltor\_diag.cu} and to an extend
\texttt{geometry\_diag.cu}. The goal is to provide
information such that a user can avoid to look
into the actual codes on the one side and connect
the presented formulas to relevant journal publications on the other.

The program \texttt{feltor/inc/geometries/geometry\_diag.cu}
analyses the magnetic field geometry.
\texttt{feltor\_hpc.cu} and \texttt{feltor.cu} are programs for global 3d isothermal electromagnetic full-F gyro-fluid simulations.
\texttt{feltor/diag/feltor\_diag.cu} is a program to analyse the output
file(s) of \texttt{feltor\_hpc.cu}.

\end{abstract}
\tableofcontents

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{The magnetic field}\label{sec:magnetic}
We assume a three-dimensional flat space with arbitrary coordinate
system $\vec x :=\{x_0, x_1, x_2\}$, metric
tensor $g_{ij}$ and volume element $\sqrt{g} := \sqrt{\det g}$.
Given a vector field $\vec B(\vec x)$ with unit vector $\bhat(\vec x) := (\vec B/B)({\vec x})$
we can define various differential operations.
%We further assume that $\bhat$ is perturbed by the parallel
%vector potential $A_\parallel$ via
%${ \vec b }_\perp := ({\vn \times A_\parallel \bhat)}/{B}$
\rowcolors{2}{gray!25}{white}
\begin{longtable}{lll>{\RaggedRight}p{7cm}}
%\toprule
\rowcolor{gray!50}\textbf{Name} &  \textbf{Symbol} & \textbf{Definition} \\
\midrule
    Perpendicular Poisson bracket&
    $\left[.,.\right]_\perp$ &
    $\left[f,g\right]_\perp := \bhat \cdot \left(\vn f \times \vn g\right) =
    b_i \varepsilon^{ijk}\partial_j f\partial_k g/\sqrt{g}$  \\
    Projection Tensor&
    $h $ & $h^{ij} := g^{ij} - b^ib^j $\\
    %Alignment Tensor&
    %$t $ & $ t^{ij} := b^ib^j$\\
    Perpendicular Gradient&
    $\np $&
    $ \np f := \bhat\times(\vn f\times \bhat ) \equiv
    h \cn f$ \\
    Perpendicular Laplacian&
    $\Delta_\perp $&
    $ \Delta_\perp f:= \vec \nc (\np f)
    = \nc( h\cn f)$  \\
    Curl-b Curvature &
    $\mathcal K_{\vn\times\bhat}$ &
    $\mathcal K_{\vn\times\bhat}(f) := \vec{ \mathcal K_{\vn\times\bhat} }\cn f = \frac{1}{B}(\vn \times \bhat)\cn f$ \\[4pt]
    Grad-B Curvature &
    $\mathcal K_{\vn B} $ &
    $\mathcal K_{\vn B}(f) := \vec{\mathcal K_{\vn B}} \cn f = \frac{1}{B}(\bhat \times \vn \ln B)\cn f$ \\[4pt]
    Curvature &
    $\mathcal K$ &
    $\mathcal{K}(f):=\vec{\mathcal K} \cn f =
     \nc\left(\frac{\bhat\times\vn f}{B}\right)$,\\[4pt]
    Parallel derivative&
    $\npar $&
    $ \npar f := \bhat\cn f$ \\
    %Perturbed parallel Derivative&
    %$\bar\npar$ &
    %$\bar\npar f := (\bhat + {\vec b }_\perp)\cn f = \npar f + A_\parallel \mathcal K_{\vn\times\bhat}(f) + \frac{1}{B}[ f, A_\parallel]_\perp$ \\
    Parallel Laplacian&
    $\Delta_\parallel $&
    $\Delta_\parallel f:= \nc ( \bhat\bhat\cn f )$\\
\bottomrule
\end{longtable}
with $b^i$ the contra- and $b_i$ the co-variant components of $\bhat$, and
$\eps^{ijk}$ the Levi-Civita symbols.
Explicit expressions for the above expressions
depend on the choice of the magnetic field and the underlying coordinate system.
Note that we have
\begin{align}
    \nc \vec{\mathcal K_{\vn\times\bhat}}
    &= -\nc \vec{\mathcal K_{\vn B}} = -\vec{ \mathcal K_{\vn\times\bhat}}\cn\ln B, \\
    \vec\nc\vec{ \mathcal K} &= 0, \\
    \vec{\mathcal K} &=
     \vn\times\frac{\bhat}{B}\cn f
    = \mathcal K_{\vn\times\bhat}(f) + \mathcal K_{\vn B}(f),\\
    \vec{ \mathcal K_{\vn\times\bhat}} - \vec{ \mathcal K_{\vn B}} &= \frac{1}{B^2} (\vn \times \vec B), \\
    \npar \ln B &= -\vec\nc\bhat.
    \label{eq:curl_curvature}
\end{align}
The last equality holds if $\vec\nc \vec B = 0$.
Note that in any arbitrary coordinate system we have
\begin{align}
(\vn f)^i = g^{ij}\partial_j f ~, \quad
\nc \vec v = \frac{1}{\sqrt{g}}\partial_i \left(\sqrt{g} v^i\right) ~, \quad
(\vec v \times \vec w)^i = \frac{1}{\sqrt{g}}\varepsilon^{ijk} v_jw_k ~.
%\label{}
\end{align}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Coordinate system}\label{sec:cylmetric}
We employ cylindrical coordinates \( (R,Z,\varphi) \), with \(\varphi\) anti directed to the geometric toroidal angle ({\bf clockwise} if viewed from above) to
obtain a right handed system. The parametric representation in Cartesian \((x,y,z)\) coordinates is therefore simply:
\begin{align}
 x &= R \hspace{1 mm} \sin{(\varphi)}, &
 y &= R \hspace{1 mm} \cos{(\varphi)}, &
 z &= Z .
\end{align}
Note here that the angle $\varphi = 0$ corresponds to the Cartesian $y$-axis.
The unit
basis vectors and (covariant) metric tensor are:
\begin{align}
 \ehat_R      &= (\sin{(\varphi)} ,   \cos{(\varphi)},0)^T, &
 \ehat_Z      &= ( 0 ,0 ,1 )^T, &
 \ehat_{\varphi} &= ( \cos{(\varphi)} , -\sin{(\varphi)} , 0 )^T,
\\
    (g_{ij}) &= \begin{pmatrix}
  1 & 0 & 0 \\
  0 & 1 & 0 \\
  0 & 0 & R^2
   \end{pmatrix}
% \vn R &= (\sin{(\varphi)} ,   \cos{(\varphi)},0 )^T , &
%  \vnZ &= ( 0 ,0 ,1 )^T,  &
%  \vn{\varphi} &= \frac{1}{R} ( \cos{(\varphi)} , -\sin{(\varphi)} , 0 )^T .
\end{align}
With the help of the metric elements we get a well behaved volume element \(\sqrt{g} = R\). However, we have a coordinate singularity at \(R=0\).
The cylindrical coordinate basis vectors are mutually orthogonal to each other.

\subsection{Solov'ev equilbrium}\label{sec:solovev}
In cylindrical coordinates the general axisymmetric  magnetic field can be written as (dimensionless)
\begin{align}
 \vec{B} &= \frac{R_0}{R}\left[I(\psi) \ehat_{\varphi} + \frac{\partial
 \psi_p}{\partial Z} \ehat_R -  \frac{\partial \psi_p}{\partial R} \ehat_Z\right] ,
\end{align}
which can obviously not be manipulated to be in Clebsch form.
Hence we are dealing with a non-flux aligned coordinate system.
For the sake of clarity we define the poloidal magnetic field \( \vec{B}_p = \frac{R_0}{R}\left( \frac{\partial \psi}{\partial Z}\ehat_R - \frac{\partial \psi}{\partial R}\ehat_Z\right)
\) and the toroidal magnetic field \(\vec{B}_t =\frac{R_0I}{R} \ehat_{\varphi}\).
Note that with a typically convex function $\psi$, $I(\psi)>0$ and the previously defined coordinate system the field line winding is a {\bf left handed screw} in the positive $\vec B$-direction.

We scaled $R$, $Z$ and $R_0$ with $\rho_s = \sqrt{T_e m_i}/(eB_0)$, the
magnetic field with $B_0$, the poloidal flux with $\psi_{p0} = B_0\rho_s \hat
R_0$ and the poloidal equilibrium current streamfunction with $I_0 = B_0 \hat R_0$ (with $\hat R_0 =
\rho_s R_0$ the dimensional major radius).
We have the equilibrium equations in toroidally symmetric, ideal MHD
$\vn p = \vec j\times \vec B$ and $\vn\times\vec B = \beta \vec j$ normalized with $p_0 = n_0 T_0$, and $j_0 = e n_0 c_S$, where we introduce $\beta = n_0 T_0 \mu_0 /B_0^2$.
Note that this normalization is in line with the one later chosen for the gyrofluid
equations but is unnatural for the MHD type equilibrium equations through the introduction
of $\rho_s$ and $\beta$.
\begin{align}
    \vn\times \vec B &= \frac{R_0}{R}\left[ -\Delta^*\psi_p\ehat_\varphi + I_Z \ehat_R - I_R\ehat_Z \right]\equiv \beta \vec j\\
 \beta j_\parallel &= \beta \vec j\cdot \bhat = \beta \frac{\d p}{\d\psi_p} \frac{I(\psi_p)}{B} +
 \frac{\d I}{\d\psi_p} B \quad \text{  Pfirsch-Schl\"uter \& Bootstrap current } \\
 \beta \vec j_\perp &= \beta \bhat\times\left(\vec j\times\bhat\right)=
 \beta \frac{\bhat \times \vn p}{B} \quad\quad\quad \text{ diamagnetic current} \\
 \beta \vec j\times\vec B &= \frac{R_0^2}{R^2}\left[ -\Delta^* \psi_p - I
     \frac{\d I}{\d \psi_p} \right]\vn\psi_p \equiv \beta \frac{\d p}{\d\psi_p}\vn\psi_p =\beta \vn p
\end{align}
from where we recover the Grad-Shafranov equation
\begin{align}\label{eq:GSEdimless}
    -\Delta^*_\perp  \psi_p &= \beta \frac{R^2}{R_0^2} \frac{d p}{d  \psi_p } + I \frac{d I}{d  \psi_p } \equiv \beta \frac{R}{R_0} j_{\hat\varphi}
\end{align}
with $\Delta^*_\perp \psi_p = R\partial_R (R^{-1}\psi_R) + \psi_{ZZ}$.
The Solov'ev assumptions consist of \(A/R_0 = -I \frac{d I}{d  \psi_p }\) and \((1-A)/R_0 = -\frac{d p}{d  \psi_p }\), where \(A\) is a constant~\cite{Cerfon2010,Cerfon2014}.
By integration over \(\psi_p\) we find
$
 p(\psi_p) = (A-1)\psi_p/R_0/\beta$,
 $I(\psi_p) = \sqrt{-2 A \psi_p/R_0 + 1}$,
 and
    $j_{\hat\varphi} = \left[(A-1)R^2/R_0^2 - A \right]/R/\beta $.
Note that if $\psi_p$, $I(\psi)$ and $p(\psi)$ are a solution to Eq.~\eqref{eq:GSEdimless}
then so are $\mathcal P_\psi \psi_p$ , $\mathcal P_\psi I(\psi_p)$ and $\mathcal P_\psi^2 p(\psi_p)$.
Also note that for $A=0$ the constant current $I$ becomes arbitrary $\mathcal P_I$.

We introduce \(\bar{R} \equiv \frac{R}{R_0}\) and \(\bar{Z} \equiv\frac{Z}{R_0}\)
and thus represent a general solution to Equation~\eqref{eq:GSEdimless} as~\cite{Cerfon2010}
\begin{subequations}
\label{eq:solovev}
\begin{align}
 \psi_p (R,Z) &= \mathcal P_{\psi} R_0 \left[ A\left( \frac{1}{2} \bar{R}^2 \ln{\bar{R}}
   - \frac{1}{8}\bar{R}^4\right)+ \frac{1}{8}\bar{R}^4
   + \sum_{i=1}^{12} c_{i}  \bar{\psi}_{pi}\right],\\
   I(\psi_p) &= \mathcal P_I\sqrt{ - 2A\frac{\psi_p}{R_0\mathcal P_{\psi}} +1},
\end{align}
\end{subequations}
with $\mathcal P_\psi$ a free constant, $\mathcal P_I = \pm \mathcal P_\psi$ for $A\neq 0$ and $\mathcal P_I$ arbitrary for $A=0$ (purely toroidal equilibrium current).
We have
\begin{align}
    p(\psi_p) = \mathcal P_\psi \frac{( A-1)\psi_p}{\beta R_0 } \qquad
    j_{\hat\varphi} = \frac{\mathcal P_\psi}{\beta } \left[\frac{(A-1)R}{R_0^2} - \frac{A}{R}\right]
\end{align}
\rowcolors{2}{gray!25}{white}
\begin{longtable}{>{\RaggedRight}p{7cm}>{\RaggedRight}p{7cm}}
\toprule
  $\bar{\psi}_{p1}=1$
  & $\bar{\psi}_{p7}=8\bar{Z}^6 -140 \bar{R}^2 \bar{Z}^4
                      + 75 \bar{R}^4 \bar{Z}^2 - 15\bar{R}^6\ln{\bar{R}}+ 180 \bar{R}^4 \bar{Z}^2 \ln{\bar{R}} \
                       -120 \bar{R}^2 \bar{Z}^4 \ln{\bar{R}}$\\
%
  $\bar{\psi}_{p2}=\bar{R}^2$ &
  $\bar{\psi}_{p8}=\bar{Z}$ \\
%<commit_msg>Add p_0 to background pressure profile<commit_after>%%%%%%%%%%%%%%%%%%%%%definitions%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\input{../../doc/related_pages/header.tex}
\input{../../doc/related_pages/newcommands.tex}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%DOCUMENT%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}

\title{
The full-F electromagnetic model in toroidal geometry \textsc{Feltor}}
\author{ M.~Wiesenberger and M.~Held}
\maketitle

\begin{abstract}
The purpose of this document is to describe the programs
\texttt{feltor\_hpc.cu, feltor.cu, feltor\_diag.cu} and to an extend
\texttt{geometry\_diag.cu}. The goal is to provide
information such that a user can avoid to look
into the actual codes on the one side and connect
the presented formulas to relevant journal publications on the other.

The program \texttt{feltor/inc/geometries/geometry\_diag.cu}
analyses the magnetic field geometry.
\texttt{feltor\_hpc.cu} and \texttt{feltor.cu} are programs for global 3d isothermal electromagnetic full-F gyro-fluid simulations.
\texttt{feltor/diag/feltor\_diag.cu} is a program to analyse the output
file(s) of \texttt{feltor\_hpc.cu}.

\end{abstract}
\tableofcontents

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{The magnetic field}\label{sec:magnetic}
We assume a three-dimensional flat space with arbitrary coordinate
system $\vec x :=\{x_0, x_1, x_2\}$, metric
tensor $g_{ij}$ and volume element $\sqrt{g} := \sqrt{\det g}$.
Given a vector field $\vec B(\vec x)$ with unit vector $\bhat(\vec x) := (\vec B/B)({\vec x})$
we can define various differential operations.
%We further assume that $\bhat$ is perturbed by the parallel
%vector potential $A_\parallel$ via
%${ \vec b }_\perp := ({\vn \times A_\parallel \bhat)}/{B}$
\rowcolors{2}{gray!25}{white}
\begin{longtable}{lll>{\RaggedRight}p{7cm}}
%\toprule
\rowcolor{gray!50}\textbf{Name} &  \textbf{Symbol} & \textbf{Definition} \\
\midrule
    Perpendicular Poisson bracket&
    $\left[.,.\right]_\perp$ &
    $\left[f,g\right]_\perp := \bhat \cdot \left(\vn f \times \vn g\right) =
    b_i \varepsilon^{ijk}\partial_j f\partial_k g/\sqrt{g}$  \\
    Projection Tensor&
    $h $ & $h^{ij} := g^{ij} - b^ib^j $\\
    %Alignment Tensor&
    %$t $ & $ t^{ij} := b^ib^j$\\
    Perpendicular Gradient&
    $\np $&
    $ \np f := \bhat\times(\vn f\times \bhat ) \equiv
    h \cn f$ \\
    Perpendicular Laplacian&
    $\Delta_\perp $&
    $ \Delta_\perp f:= \vec \nc (\np f)
    = \nc( h\cn f)$  \\
    Curl-b Curvature &
    $\mathcal K_{\vn\times\bhat}$ &
    $\mathcal K_{\vn\times\bhat}(f) := \vec{ \mathcal K_{\vn\times\bhat} }\cn f = \frac{1}{B}(\vn \times \bhat)\cn f$ \\[4pt]
    Grad-B Curvature &
    $\mathcal K_{\vn B} $ &
    $\mathcal K_{\vn B}(f) := \vec{\mathcal K_{\vn B}} \cn f = \frac{1}{B}(\bhat \times \vn \ln B)\cn f$ \\[4pt]
    Curvature &
    $\mathcal K$ &
    $\mathcal{K}(f):=\vec{\mathcal K} \cn f =
     \nc\left(\frac{\bhat\times\vn f}{B}\right)$,\\[4pt]
    Parallel derivative&
    $\npar $&
    $ \npar f := \bhat\cn f$ \\
    %Perturbed parallel Derivative&
    %$\bar\npar$ &
    %$\bar\npar f := (\bhat + {\vec b }_\perp)\cn f = \npar f + A_\parallel \mathcal K_{\vn\times\bhat}(f) + \frac{1}{B}[ f, A_\parallel]_\perp$ \\
    Parallel Laplacian&
    $\Delta_\parallel $&
    $\Delta_\parallel f:= \nc ( \bhat\bhat\cn f )$\\
\bottomrule
\end{longtable}
with $b^i$ the contra- and $b_i$ the co-variant components of $\bhat$, and
$\eps^{ijk}$ the Levi-Civita symbols.
Explicit expressions for the above expressions
depend on the choice of the magnetic field and the underlying coordinate system.
Note that we have
\begin{align}
    \nc \vec{\mathcal K_{\vn\times\bhat}}
    &= -\nc \vec{\mathcal K_{\vn B}} = -\vec{ \mathcal K_{\vn\times\bhat}}\cn\ln B, \\
    \vec\nc\vec{ \mathcal K} &= 0, \\
    \vec{\mathcal K} &=
     \vn\times\frac{\bhat}{B}\cn f
    = \mathcal K_{\vn\times\bhat}(f) + \mathcal K_{\vn B}(f),\\
    \vec{ \mathcal K_{\vn\times\bhat}} - \vec{ \mathcal K_{\vn B}} &= \frac{1}{B^2} (\vn \times \vec B), \\
    \npar \ln B &= -\vec\nc\bhat.
    \label{eq:curl_curvature}
\end{align}
The last equality holds if $\vec\nc \vec B = 0$.
Note that in any arbitrary coordinate system we have
\begin{align}
(\vn f)^i = g^{ij}\partial_j f ~, \quad
\nc \vec v = \frac{1}{\sqrt{g}}\partial_i \left(\sqrt{g} v^i\right) ~, \quad
(\vec v \times \vec w)^i = \frac{1}{\sqrt{g}}\varepsilon^{ijk} v_jw_k ~.
%\label{}
\end{align}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Coordinate system}\label{sec:cylmetric}
We employ cylindrical coordinates \( (R,Z,\varphi) \), with \(\varphi\) anti directed to the geometric toroidal angle ({\bf clockwise} if viewed from above) to
obtain a right handed system. The parametric representation in Cartesian \((x,y,z)\) coordinates is therefore simply:
\begin{align}
 x &= R \hspace{1 mm} \sin{(\varphi)}, &
 y &= R \hspace{1 mm} \cos{(\varphi)}, &
 z &= Z .
\end{align}
Note here that the angle $\varphi = 0$ corresponds to the Cartesian $y$-axis.
The unit
basis vectors and (covariant) metric tensor are:
\begin{align}
 \ehat_R      &= (\sin{(\varphi)} ,   \cos{(\varphi)},0)^T, &
 \ehat_Z      &= ( 0 ,0 ,1 )^T, &
 \ehat_{\varphi} &= ( \cos{(\varphi)} , -\sin{(\varphi)} , 0 )^T,
\\
    (g_{ij}) &= \begin{pmatrix}
  1 & 0 & 0 \\
  0 & 1 & 0 \\
  0 & 0 & R^2
   \end{pmatrix}
% \vn R &= (\sin{(\varphi)} ,   \cos{(\varphi)},0 )^T , &
%  \vnZ &= ( 0 ,0 ,1 )^T,  &
%  \vn{\varphi} &= \frac{1}{R} ( \cos{(\varphi)} , -\sin{(\varphi)} , 0 )^T .
\end{align}
With the help of the metric elements we get a well behaved volume element \(\sqrt{g} = R\). However, we have a coordinate singularity at \(R=0\).
The cylindrical coordinate basis vectors are mutually orthogonal to each other.

\subsection{Solov'ev equilbrium}\label{sec:solovev}
In cylindrical coordinates the general axisymmetric  magnetic field can be written as (dimensionless)
\begin{align}
 \vec{B} &= \frac{R_0}{R}\left[I(\psi) \ehat_{\varphi} + \frac{\partial
 \psi_p}{\partial Z} \ehat_R -  \frac{\partial \psi_p}{\partial R} \ehat_Z\right] ,
\end{align}
which can obviously not be manipulated to be in Clebsch form.
Hence we are dealing with a non-flux aligned coordinate system.
For the sake of clarity we define the poloidal magnetic field \( \vec{B}_p = \frac{R_0}{R}\left( \frac{\partial \psi}{\partial Z}\ehat_R - \frac{\partial \psi}{\partial R}\ehat_Z\right)
\) and the toroidal magnetic field \(\vec{B}_t =\frac{R_0I}{R} \ehat_{\varphi}\).
Note that with a typically convex function $\psi$, $I(\psi)>0$ and the previously defined coordinate system the field line winding is a {\bf left handed screw} in the positive $\vec B$-direction.

We scaled $R$, $Z$ and $R_0$ with $\rho_s = \sqrt{T_e m_i}/(eB_0)$, the
magnetic field with $B_0$, the poloidal flux with $\psi_{p0} = B_0\rho_s \hat
R_0$ and the poloidal equilibrium current streamfunction with $I_0 = B_0 \hat R_0$ (with $\hat R_0 =
\rho_s R_0$ the dimensional major radius).
We have the equilibrium equations in toroidally symmetric, ideal MHD
$\vn p = \vec j\times \vec B$ and $\vn\times\vec B = \beta \vec j$ normalized with $p_0 = n_0 T_0$, and $j_0 = e n_0 c_S$, where we introduce $\beta = n_0 T_0 \mu_0 /B_0^2$.
Note that this normalization is in line with the one later chosen for the gyrofluid
equations but is unnatural for the MHD type equilibrium equations through the introduction
of $\rho_s$ and $\beta$.
\begin{align}
    \vn\times \vec B &= \frac{R_0}{R}\left[ -\Delta^*\psi_p\ehat_\varphi + I_Z \ehat_R - I_R\ehat_Z \right]\equiv \beta \vec j\\
 \beta j_\parallel &= \beta \vec j\cdot \bhat = \beta \frac{\d p}{\d\psi_p} \frac{I(\psi_p)}{B} +
 \frac{\d I}{\d\psi_p} B \quad \text{  Pfirsch-Schl\"uter \& Bootstrap current } \\
 \beta \vec j_\perp &= \beta \bhat\times\left(\vec j\times\bhat\right)=
 \beta \frac{\bhat \times \vn p}{B} \quad\quad\quad \text{ diamagnetic current} \\
 \beta \vec j\times\vec B &= \frac{R_0^2}{R^2}\left[ -\Delta^* \psi_p - I
     \frac{\d I}{\d \psi_p} \right]\vn\psi_p \equiv \beta \frac{\d p}{\d\psi_p}\vn\psi_p =\beta \vn p
\end{align}
from where we recover the Grad-Shafranov equation
\begin{align}\label{eq:GSEdimless}
    -\Delta^*_\perp  \psi_p &= \beta \frac{R^2}{R_0^2} \frac{d p}{d  \psi_p } + I \frac{d I}{d  \psi_p } \equiv \beta \frac{R}{R_0} j_{\hat\varphi}
\end{align}
with $\Delta^*_\perp \psi_p = R\partial_R (R^{-1}\psi_R) + \psi_{ZZ}$.
The Solov'ev assumptions consist of \(A/R_0 = -I \frac{d I}{d  \psi_p }\) and \((1-A)/R_0 = -\frac{d p}{d  \psi_p }\), where \(A\) is a constant~\cite{Cerfon2010,Cerfon2014}.
By integration over \(\psi_p\) we find
$
p(\psi_p) = (A-1)\psi_p/R_0/\beta + p(0)$,
 $I(\psi_p) = \sqrt{-2 A \psi_p/R_0 + 1}$,
 and
    $j_{\hat\varphi} = \left[(A-1)R^2/R_0^2 - A \right]/R/\beta $.
Note that if $\psi_p$, $I(\psi)$ and $p(\psi)$ are a solution to Eq.~\eqref{eq:GSEdimless}
then so are $\mathcal P_\psi \psi_p$ , $\mathcal P_\psi I(\psi_p)$ and $\mathcal P_\psi^2 p(\psi_p)$.
Also note that for $A=0$ the constant current $I$ becomes arbitrary $\mathcal P_I$.

We introduce \(\bar{R} \equiv \frac{R}{R_0}\) and \(\bar{Z} \equiv\frac{Z}{R_0}\)
and thus represent a general solution to Equation~\eqref{eq:GSEdimless} as~\cite{Cerfon2010}
\begin{subequations}
\label{eq:solovev}
\begin{align}
 \psi_p (R,Z) &= \mathcal P_{\psi} R_0 \left[ A\left( \frac{1}{2} \bar{R}^2 \ln{\bar{R}}
   - \frac{1}{8}\bar{R}^4\right)+ \frac{1}{8}\bar{R}^4
   + \sum_{i=1}^{12} c_{i}  \bar{\psi}_{pi}\right],\\
   I(\psi_p) &= \mathcal P_I\sqrt{ - 2A\frac{\psi_p}{R_0\mathcal P_{\psi}} +1},
\end{align}
\end{subequations}
with $\mathcal P_\psi$ a free constant, $\mathcal P_I = \pm \mathcal P_\psi$ for $A\neq 0$ and $\mathcal P_I$ arbitrary for $A=0$ (purely toroidal equilibrium current).
We have
\begin{align}
    p(\psi_p) = \mathcal P_\psi \frac{( A-1)\psi_p}{\beta R_0 } + p(0) \qquad
    j_{\hat\varphi} = \frac{\mathcal P_\psi}{\beta } \left[\frac{(A-1)R}{R_0^2} - \frac{A}{R}\right]
\end{align}
\rowcolors{2}{gray!25}{white}
\begin{longtable}{>{\RaggedRight}p{7cm}>{\RaggedRight}p{7cm}}
\toprule
  $\bar{\psi}_{p1}=1$
  & $\bar{\psi}_{p7}=8\bar{Z}^6 -140 \bar{R}^2 \bar{Z}^4
                      + 75 \bar{R}^4 \bar{Z}^2 - 15\bar{R}^6\ln{\bar{R}}+ 180 \bar{R}^4 \bar{Z}^2 \ln{\bar{R}} \
                       -120 \bar{R}^2 \bar{Z}^4 \ln{\bar{R}}$\\
%
  $\bar{\psi}_{p2}=\bar{R}^2$ &
  $\bar{\psi}_{p8}=\bar{Z}$ \\
%
{'fraction_non_alphanumeric': 0.21883709754925518, 'fraction_numerical': 0.016098029793368572, 'mean_word_length': 3.3329169269206744, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5485828', 'n_tokens_mistral': 8099, 'n_tokens_neox': 7728, 'n_words': 2177}