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

Stellarator magnetic field with cubic spline interpolation. More...

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include "../ascot5.h"
#include "../error.h"
#include "../print.h"
#include "../consts.h"
#include "B_STS.h"
#include "../linint/linint.h"
#include "../spline/interp.h"

Go to the source code of this file.

Functions

int B_STS_init_offload (B_STS_offload_data *offload_data, real **offload_array)
 Initialize magnetic field offload data.
 
void B_STS_free_offload (B_STS_offload_data *offload_data, real **offload_array)
 Free offload array.
 
void B_STS_init (B_STS_data *Bdata, B_STS_offload_data *offload_data, real *offload_array)
 Initialize magnetic field data struct on target.
 
a5err B_STS_eval_psi (real *psi, real r, real phi, real z, B_STS_data *Bdata)
 Evaluate poloidal flux psi.
 
a5err B_STS_eval_psi_dpsi (real psi_dpsi[4], real r, real phi, real z, B_STS_data *Bdata)
 Evaluate poloidal flux psi and its derivatives.
 
a5err B_STS_eval_rho_drho (real rho_drho[4], real r, real phi, real z, B_STS_data *Bdata)
 Evaluate normalized poloidal flux rho and its derivatives.
 
a5err B_STS_eval_B (real B[3], real r, real phi, real z, B_STS_data *Bdata)
 Evaluate magnetic field.
 
a5err B_STS_eval_B_dB (real B_dB[12], real r, real phi, real z, B_STS_data *Bdata)
 Evaluate magnetic field and its derivatives.
 
a5err B_STS_get_axis_rz (real rz[2], B_STS_data *Bdata, real phi)
 Return magnetic axis Rz-coordinates.
 

Detailed Description

Stellarator magnetic field with cubic spline interpolation.

This module represents a magnetic field where data is given in $R\phi z$- grid from which it is interpolated with tricubic splines.

The magnetic field is evaluated from magnetic field strength $\mathbf{B}$ which may not be divergence free. The poloidal magnetic flux $\psi$ is interpolated using tricubic splines as well. $\psi$ and $\mathbf{B}$ are given in separate grids.

The magnetic axis location for stellarators varies with the $\phi$ angle and is evaluated using linear interpolation.

This module does no extrapolation so if queried value is outside the $Rz$-grid an error is thrown. The $\phi$-grid is assumed to be periodic. Periodic boundary conditions are used but it is user's responsibility to provide input whose $\phi$-grid makes sense (in that it actually represents a periodic field), i.e., $\phi_\mathrm{max}-\phi_\mathrm{min} = 2\pi/(N+1)$. However, do note that in this module $\phi_\mathrm{max}$ is not the "last" grid point but the second last, e.g. if $\phi_\mathrm{min}=0$ and $n_\phi = 360$, then $\phi_\mathrm{max}=359$ if periodicity is $N=0$.

See also
B_field.c linint1D.c

Definition in file B_STS.c.

Function Documentation

◆ B_STS_init_offload()

int B_STS_init_offload ( B_STS_offload_data * offload_data,
real ** offload_array )

Initialize magnetic field offload data.

This function takes pre-initialized offload data struct and offload array as inputs. The data is used to fill rest of the offload struct and to construct bicubic splines whose coefficients are stored in re-allocated offload array.

The offload data struct must have the following fields initialized:

B_STS_offload_data.offload_array_length is set here.

The offload array must contain the following data:

  • offload_array[ z*Bn_r*Bn_z + j*Bn_r + i] = B_R(R_i, phi_z, z_j) [T]
  • offload_array[ Bn_r*Bn_z*Bn_phi + z*Bn_r*Bn_z + j*Bn_r + i] = B_phi(R_i, phi_z, z_j) [T]
  • offload_array[2*Bn_r*Bn_z*Bn_phi + z*Bn_r*Bn_z + j*Bn_r + i] = B_z(R_i, phi_z, z_j) [T]
  • offload_array[3*Bn_r*Bn_z*Bn_phi + z*psin_r*psin_z + j*psin_r + i] = psi(R_i, phi_z, z_j) [V*s*m^-1]
  • offload_array[3*Bn_r*Bn_z*Bn_phi + psin_r*psin_z*psin_phi + z] = axis_R(phi_z) [m]
  • offload_array[3*Bn_r*Bn_z*Bn_phi + psin_r*psin_z*psin_phi + n_axis + z] = axis_z(phi_z) [m]

Sanity checks are printed if data was initialized succesfully.

Parameters
offload_datapointer to offload data struct
offload_arraypointer to offload array which is reallocated here
Returns
zero if initialization succeeded

Definition at line 98 of file B_STS.c.

◆ B_STS_free_offload()

void B_STS_free_offload ( B_STS_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 225 of file B_STS.c.

◆ B_STS_init()

void B_STS_init ( B_STS_data * Bdata,
B_STS_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 237 of file B_STS.c.

◆ B_STS_eval_psi()

a5err B_STS_eval_psi ( real * psi,
real r,
real phi,
real z,
B_STS_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 322 of file B_STS.c.

◆ B_STS_eval_psi_dpsi()

a5err B_STS_eval_psi_dpsi ( real psi_dpsi[4],
real r,
real phi,
real z,
B_STS_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 354 of file B_STS.c.

◆ B_STS_eval_rho_drho()

a5err B_STS_eval_rho_drho ( real rho_drho[4],
real r,
real phi,
real z,
B_STS_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 396 of file B_STS.c.

◆ B_STS_eval_B()

a5err B_STS_eval_B ( real B[3],
real r,
real phi,
real z,
B_STS_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 445 of file B_STS.c.

◆ B_STS_eval_B_dB()

a5err B_STS_eval_B_dB ( real B_dB[12],
real r,
real phi,
real z,
B_STS_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 480 of file B_STS.c.

◆ B_STS_get_axis_rz()

a5err B_STS_get_axis_rz ( real rz[2],
B_STS_data * Bdata,
real phi )

Return magnetic axis Rz-coordinates.

Parameters
rzpointer where axis R and z [m] values will be stored
Bdatapointer to magnetic field data struct
phiphi coordinate [deg]
Returns
Non-zero a5err value if evaluation failed, zero otherwise

Definition at line 531 of file B_STS.c.