ASCOT5
Loading...
Searching...
No Matches
B_2DS.c File Reference

2D magnetic field with bicubic spline interpolation More...

#include <stdlib.h>
#include <math.h>
#include "../ascot5.h"
#include "../error.h"
#include "../print.h"
#include "B_2DS.h"
#include "../spline/interp.h"

Go to the source code of this file.

Functions

int B_2DS_init (B_2DS_data *data, int n_r, real r_min, real r_max, int n_z, real z_min, real z_max, real axis_r, real axis_z, real psi0, real psi1, real *psi, real *B_r, real *B_phi, real *B_z)
 Initialize magnetic field data.
 
void B_2DS_free (B_2DS_data *data)
 Free allocated resources.
 
void B_2DS_offload (B_2DS_data *data)
 Offload data to the accelerator.
 
a5err B_2DS_eval_psi (real *psi, real r, real phi, real z, B_2DS_data *Bdata)
 Evaluate poloidal flux psi.
 
a5err B_2DS_eval_psi_dpsi (real psi_dpsi[4], real r, real phi, real z, B_2DS_data *Bdata)
 Evaluate poloidal flux psi and its derivatives.
 
a5err B_2DS_eval_rho_drho (real rho_drho[4], real r, real phi, real z, B_2DS_data *Bdata)
 Evaluate normalized poloidal flux rho and its derivatives.
 
a5err B_2DS_eval_B (real B[3], real r, real phi, real z, B_2DS_data *Bdata)
 Evaluate magnetic field.
 
a5err B_2DS_eval_B_dB (real B_dB[12], real r, real phi, real z, B_2DS_data *Bdata)
 Evaluate magnetic field and its derivatives.
 
a5err B_2DS_get_axis_rz (real rz[2], B_2DS_data *Bdata)
 Return magnetic axis R-coordinate.
 

Detailed Description

2D magnetic field with bicubic spline interpolation

This module represents a magnetic field where data is given in $Rz$-grid from which it is interpolated with bicubic splines. The field is axisymmetric.

The magnetic field is evaluated from magnetic field strength $\mathbf{B}$ which may not be divergence free. However, $B_R$ and $B_z$ components are also evaluated from poloidal magnetic flux $\psi$ as

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

The total field is then a sum of components interpolated directly from $\mathbf{B}$ and components calculated via interpolated $\psi$.

This module does no extrapolation so if queried value is outside the $Rz$-grid an error is thrown.

See also
B_field.c

Definition in file B_2DS.c.

Function Documentation

◆ B_2DS_init()

int B_2DS_init ( B_2DS_data * data,
int n_r,
real r_min,
real r_max,
int n_z,
real z_min,
real z_max,
real axis_r,
real axis_z,
real psi0,
real psi1,
real * psi,
real * B_r,
real * B_phi,
real * B_z )

Initialize magnetic field data.

Parameters
n_rnumber of r grid points
r_minminimum R coordinate in the grid [m]
r_maxmaximum R coordinate in the grid [m]
n_znumber of z grid points
z_minminimum z coordinate in the grid [m]
z_maxmaximum z coordinate in the grid [m]
axis_rR coordinate of magnetic axis [m]
axis_zz coordinate of magnetic axis [m]
psi0poloidal flux at magnetic axis [Vs/m]
psi1poloidal flux at separatrix [Vs/m]
psipoloidal flux psi(R_i,z_j) = arr[j*n_r + i] [Vs/m]
B_rMagnetic field R component B_r(R_i,z_j) = arr[j*n_r + i] [T]
B_phiMagnetic field phi component B_phi(R_i,z_j) = arr[j*n_r + i] [T]
B_zMagnetic field z component B_z(R_i,z_j) = arr[j*n_r + i] [T]
Returns
zero if initialization succeeded

Definition at line 55 of file B_2DS.c.

◆ B_2DS_free()

void B_2DS_free ( B_2DS_data * data)

Free allocated resources.

Parameters
datapointer to data struct

Definition at line 125 of file B_2DS.c.

◆ B_2DS_offload()

void B_2DS_offload ( B_2DS_data * data)

Offload data to the accelerator.

Parameters
datapointer to the data struct

Definition at line 137 of file B_2DS.c.

◆ B_2DS_eval_psi()

a5err B_2DS_eval_psi ( real * psi,
real r,
real phi,
real z,
B_2DS_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
Non-zero a5err value if evaluation failed, zero otherwise

Definition at line 158 of file B_2DS.c.

◆ B_2DS_eval_psi_dpsi()

a5err B_2DS_eval_psi_dpsi ( real psi_dpsi[4],
real r,
real phi,
real z,
B_2DS_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
Non-zero a5err value if evaluation failed, zero otherwise

Definition at line 181 of file B_2DS.c.

◆ B_2DS_eval_rho_drho()

a5err B_2DS_eval_rho_drho ( real rho_drho[4],
real r,
real phi,
real z,
B_2DS_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
Non-zero a5err value if evaluation failed, zero otherwise

Definition at line 212 of file B_2DS.c.

◆ B_2DS_eval_B()

a5err B_2DS_eval_B ( real B[3],
real r,
real phi,
real z,
B_2DS_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
Non-zero a5err value if evaluation failed, zero otherwise

Definition at line 250 of file B_2DS.c.

◆ B_2DS_eval_B_dB()

a5err B_2DS_eval_B_dB ( real B_dB[12],
real r,
real phi,
real z,
B_2DS_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
Non-zero a5err value if evaluation failed, zero otherwise

Definition at line 296 of file B_2DS.c.

◆ B_2DS_get_axis_rz()

a5err B_2DS_get_axis_rz ( real rz[2],
B_2DS_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 365 of file B_2DS.c.