ASCOT5
Loading...
Searching...
No Matches
Functions
B_GS.c File Reference

Analytic magnetic field. More...

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "../ascot5.h"
#include "../consts.h"
#include "../print.h"
#include "../error.h"
#include "B_GS.h"

Go to the source code of this file.

Functions

int B_GS_init_offload (B_GS_offload_data *offload_data, real **offload_array)
 Initialize magnetic field offload data.
 
void B_GS_free_offload (B_GS_offload_data *offload_data, real **offload_array)
 Free offload array.
 
void B_GS_init (B_GS_data *Bdata, B_GS_offload_data *offload_data, real *offload_array)
 Initialize magnetic field data struct on target.
 
a5err B_GS_eval_psi (real *psi, real r, real phi, real z, B_GS_data *Bdata)
 Evaluate poloidal flux psi.
 
a5err B_GS_eval_psi_dpsi (real psi_dpsi[4], real r, real phi, real z, B_GS_data *Bdata)
 Evaluate poloidal flux psi and its derivatives.
 
a5err B_GS_eval_rho_drho (real rho_drho[4], real r, real phi, real z, B_GS_data *Bdata)
 Evaluate normalized poloidal flux rho and its derivatives.
 
a5err B_GS_eval_B (real B[3], real r, real phi, real z, B_GS_data *Bdata)
 Evaluate magnetic field.
 
a5err B_GS_eval_B_dB (real B_dB[12], real r, real phi, real z, B_GS_data *Bdata)
 Evaluate magnetic field and its derivatives.
 
a5err B_GS_get_axis_rz (real rz[2], B_GS_data *Bdata)
 Return magnetic axis R-coordinate.
 

Detailed Description

Analytic magnetic field.

This module implements a toroidal magnetic field based on an analytical solution to the Grad-Shafranov equation [1].

In this model, the poloidal flux psi is calculated as

\begin{align*}
\psi(R,Z) =
&\psi_c [(1-A) (r^4/8)                                         \\
&+ A (r^2\log(r)/2)                                            \\
&+ c_0                                                         \\
&+ c_1 (r^2)                                                   \\
&+ c_2 (r^2\log(r) - z^2)                                      \\
&+ c_3 (r^4 - 4r^2z^2)                                         \\
&+ c_4 (3r^4\log(r) - 9r^2z^2 - 12r^2\log(r)z^2 + 2z^4)        \\
&+ c_5 (r^6 - 12r^4z^2 + 8r^2z^4)                              \\
&+ c_6 (8z^6 - 140r^2z^4 - 120r^2\log(r)z^4 + 180r^4\log(r)z^2
                      + 75r^4z^2 - 15r^6\log(r))               \\
&+ c_7  (z)                                                    \\
&+ c_8  (zr^2)                                                 \\
&+ c_9  (z^3 - 3zr^2\log(r))                                   \\
&+ c_{10} (3zr^4 - 4z^3r^2)                                    \\
&+ c_{12} (8z^5 - 45zr^4 - 80z^3r^2\log(r) + 60zr^4\log(r)) ]
\end{align*}

where $c_i$ and $A$ are pre-calculated coefficients which can be chosen so that realistic equilibria resembling different machines are produced. The equilibrium can be non-symmetric with respect to magnetic plane, and can have zero, one, or two X-points. $\psi_c$ is a scaling constant, and $r = R/R_0$ $z = Z/R_0$. From $\psi$ the poloidal magnetic field components can be evaluated from Grad-Shafranov relations

\begin{align*}
B_R &= -\frac{1}{R}\frac{\partial\psi}{\partial z}\\
B_z &= \frac{1}{R}\frac{\partial\psi}{\partial R}
\end{align*}

and toroidal field is evaluated as

\begin{equation*}
B_\phi = \frac{B_0R_0}{R}
\end{equation*}

This module also includes the possibility to have an analytical model for toroidal field ripple, which is used if ripple period $N>0$. The rippled toroidal field is

\begin{equation*}
\tilde{B}_\phi = B_\phi( 1 + \delta\cos(N\phi) )
\end{equation*}

where

\begin{equation*}
\delta = \delta_0 \frac{r'}{a_0}^{\alpha_0}  e^{-\theta^2}
\end{equation*}

and $\theta = \arctan(Z - z_0, R- R_0)$ and $r' = \sqrt{(R-R_0)^2 + (Z-Z_0)^2}$.

[1] A.J. Cerfon, J.P. Freidberg. "One size fits all" analytic solutions to the Grad-Shafranov equation. Physics of Plasmas 17 (3) (2010) 032502. http://scitation.aip.org/content/aip/journal/pop/17/3/10.1063/1.3328818

Definition in file B_GS.c.

Function Documentation

◆ B_GS_init_offload()

int B_GS_init_offload ( B_GS_offload_data * offload_data,
real ** offload_array )

Initialize magnetic field offload data.

The offload data struct is very simple and contains only the necessary fields which are all initialized when the data is read (except B_GS.offload_array_length). The offload array is not required at all. Therefore, this function only sets the offload_array_length to zero, assigns a NULL pointer to offload_array, and prints sanity checks so that user may verify that data was initialized succesfully.

Parameters
offload_datapointer to offload data struct
offload_arraypointer to offload array
Returns
zero to indicate success

Definition at line 91 of file B_GS.c.

◆ B_GS_free_offload()

void B_GS_free_offload ( B_GS_offload_data * offload_data,
real ** offload_array )

Free offload array.

Parameters
offload_datapointer to offload data struct
offload_arraypointer to pointer to offload array

Definition at line 131 of file B_GS.c.

◆ B_GS_init()

void B_GS_init ( B_GS_data * Bdata,
B_GS_offload_data * offload_data,
real * offload_array )

Initialize magnetic field data struct on target.

Parameters
Bdatapointer to data struct on target
offload_datapointer to offload data struct
offload_arrayoffload array

Definition at line 144 of file B_GS.c.

◆ B_GS_eval_psi()

a5err B_GS_eval_psi ( real * psi,
real r,
real phi,
real z,
B_GS_data * Bdata )

Evaluate poloidal flux psi.

Parameters
psipointer where psi [V*s*m^-1] value will be stored
rR coordinate [m]
phiphi coordinate [rad]
zz coordinate [m]
Bdatapointer to magnetic field data struct
Returns
zero to indicate success

Definition at line 174 of file B_GS.c.

◆ B_GS_eval_psi_dpsi()

a5err B_GS_eval_psi_dpsi ( real psi_dpsi[4],
real r,
real phi,
real z,
B_GS_data * Bdata )

Evaluate poloidal flux psi and its derivatives.

Parameters
psi_dpsipointer for storing psi [V*s*m^-1] and its derivatives
rR coordinate [m]
phiphi coordinate [rad]
zz coordinate [m]
Bdatapointer to magnetic field data struct
Returns
zero to indicate success

Definition at line 227 of file B_GS.c.

◆ B_GS_eval_rho_drho()

a5err B_GS_eval_rho_drho ( real rho_drho[4],
real r,
real phi,
real z,
B_GS_data * Bdata )

Evaluate normalized poloidal flux rho and its derivatives.

Parameters
rho_drhopointer where rho and its derivatives will be stored
rR coordinate [m]
phiphi coordinate [rad]
zz coordinate [m]
Bdatapointer to magnetic field data struct
Returns
zero to indicate success

Definition at line 296 of file B_GS.c.

◆ B_GS_eval_B()

a5err B_GS_eval_B ( real B[3],
real r,
real phi,
real z,
B_GS_data * Bdata )

Evaluate magnetic field.

Parameters
Bpointer to array where magnetic field values are stored
rR coordinate [m]
phiphi coordinate [deg]
zz coordinate [m]
Bdatapointer to magnetic field data struct
Returns
zero to indicate success

Definition at line 327 of file B_GS.c.

◆ B_GS_eval_B_dB()

a5err B_GS_eval_B_dB ( real B_dB[12],
real r,
real phi,
real z,
B_GS_data * Bdata )

Evaluate magnetic field and its derivatives.

Parameters
B_dBpointer to array where the field and its derivatives are stored
rR coordinate [m]
phiphi coordinate [deg]
zz coordinate [m]
Bdatapointer to magnetic field data struct
Returns
zero to indicate success

Definition at line 406 of file B_GS.c.

◆ B_GS_get_axis_rz()

a5err B_GS_get_axis_rz ( real rz[2],
B_GS_data * Bdata )

Return magnetic axis R-coordinate.

Parameters
rzpointer where axis R and z [m] values will be stored
Bdatapointer to magnetic field data struct
Returns
Zero a5err value as this function can't fail.

Definition at line 557 of file B_GS.c.