ASCOT5
Loading...
Searching...
No Matches
Data Structures | Typedefs | Enumerations | Functions
B_field.h File Reference

Header file for B_field.c. More...

#include "offload_acc_omp.h"
#include "ascot5.h"
#include "error.h"
#include "Bfield/B_GS.h"
#include "Bfield/B_2DS.h"
#include "Bfield/B_3DS.h"
#include "Bfield/B_STS.h"
#include "Bfield/B_TC.h"

Go to the source code of this file.

Data Structures

struct  B_field_offload_data
 Magnetic field offload data. More...
 
struct  B_field_data
 Magnetic field simulation data. More...
 

Typedefs

typedef enum B_field_type B_field_type
 Magnetic field types.
 

Enumerations

enum  B_field_type {
  B_field_type_GS , B_field_type_2DS , B_field_type_3DS , B_field_type_STS ,
  B_field_type_TC
}
 Magnetic field types. More...
 

Functions

int B_field_init_offload (B_field_offload_data *offload_data, real **offload_array)
 Load magnetic field data and prepare parameters.
 
void B_field_free_offload (B_field_offload_data *offload_data, real **offload_array)
 Free offload array and reset parameters.
 
int B_field_init (B_field_data *Bdata, B_field_offload_data *offload_data, real *offload_array)
 Initialize magnetic field data struct on target.
 
a5err B_field_eval_psi (real *psi, real r, real phi, real z, real t, B_field_data *Bdata)
 Evaluate poloidal flux psi.
 
DECLARE_TARGET_END a5err B_field_eval_psi_dpsi (real psi_dpsi[4], real r, real phi, real z, real t, B_field_data *Bdata)
 Evaluate poloidal flux psi and its derivatives.
 
DECLARE_TARGET_END a5err B_field_eval_rho (real rho[2], real psi, B_field_data *Bdata)
 Evaluate normalized poloidal flux rho and its psi derivative.
 
DECLARE_TARGET_END a5err B_field_eval_rho_drho (real rho_drho[4], real r, real phi, real z, B_field_data *Bdata)
 Evaluate normalized poloidal flux rho and its derivatives.
 
DECLARE_TARGET_END a5err B_field_eval_B (real B[3], real r, real phi, real z, real t, B_field_data *Bdata)
 Evaluate magnetic field.
 
DECLARE_TARGET_END a5err B_field_eval_B_dB (real B_dB[15], real r, real phi, real z, real t, B_field_data *Bdata)
 Evaluate magnetic field and its derivatives.
 
DECLARE_TARGET_END a5err B_field_get_axis_rz (real rz[2], B_field_data *Bdata, real phi)
 Return magnetic axis Rz-coordinates.
 

Detailed Description

Header file for B_field.c.

Contains a list declaring all B_field_types, and declaration of B_field_offload_data and B_field_data structs.

Definition in file B_field.h.

Typedef Documentation

◆ B_field_type

typedef enum B_field_type B_field_type

Magnetic field types.

Magnetic field types are used in the magnetic field interface (B_field.c) to direct function calls to correct magnetic field instances. Each magnetic field instance must have a corresponding type.

Enumeration Type Documentation

◆ B_field_type

Magnetic field types.

Magnetic field types are used in the magnetic field interface (B_field.c) to direct function calls to correct magnetic field instances. Each magnetic field instance must have a corresponding type.

Enumerator
B_field_type_GS 

Analytic magnetic field

B_field_type_2DS 

Spline-interpolated axisymmetric magnetic field

B_field_type_3DS 

Spline-interpolated 3D magnetic field

B_field_type_STS 

Spline-interpolated stellarator magnetic field

B_field_type_TC 

Trivial Cartesian magnetic field

Definition at line 27 of file B_field.h.

Function Documentation

◆ B_field_init_offload()

int B_field_init_offload ( B_field_offload_data * offload_data,
real ** offload_array )

Load magnetic field data and prepare parameters.

This function fills the relevant magnetic field offload struct with parameters and allocates and fills the offload array. Sets offload array length in the offload struct.

The offload data has to have a type when this function is called as it should be set when the offload data is constructed from inputs.

This function is host only.

Parameters
offload_datapointer to offload data struct
offload_arraypointer to pointer to offload array
Returns
Zero if initialization succeeded

Definition at line 44 of file B_field.c.

◆ B_field_free_offload()

void B_field_free_offload ( B_field_offload_data * offload_data,
real ** offload_array )

Free offload array and reset parameters.

This function deallocates the offload_array.

This function is host only.

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

Definition at line 105 of file B_field.c.

◆ B_field_init()

int B_field_init ( B_field_data * Bdata,
B_field_offload_data * offload_data,
real * offload_array )

Initialize magnetic field data struct on target.

This function copies the magnetic field parameters from the offload struct to the struct on target and sets the magnetic field data pointers to correct offsets in the offload array.

Parameters
Bdatapointer to data struct on target
offload_datapointer to offload data struct
offload_arrayoffload array
Returns
Zero if initialization succeeded

Definition at line 143 of file B_field.c.

◆ B_field_eval_psi()

a5err B_field_eval_psi ( real * psi,
real r,
real phi,
real z,
real t,
B_field_data * Bdata )

Evaluate poloidal flux psi.

This function evaluates the poloidal flux psi at the given coordinates. The psi is exactly as it appears in Grad-Shafranov equation.

This is a SIMD function.

Parameters
psipointer where psi [V*s*m^-1] value will be stored
rR coordinate [m]
phiphi coordinate [rad]
zz coordinate [m]
ttime coordinate [s]
Bdatapointer to magnetic field data struct
Returns
Non-zero a5err value if evaluation failed, zero otherwise

Definition at line 201 of file B_field.c.

◆ B_field_eval_psi_dpsi()

DECLARE_TARGET_END a5err B_field_eval_psi_dpsi ( real psi_dpsi[4],
real r,
real phi,
real z,
real t,
B_field_data * Bdata )

Evaluate poloidal flux psi and its derivatives.

This function evaluates the poloidal flux psi and its derivatives at the given coordinates. The psi is exactly as it appears in Grad-Shafranov equation.

The values are stored in the given array as:

  • psi_dpsi[0] = psi
  • psi_dpsi[1] = dpsi/dr
  • psi_dpsi[2] = dpsi/dphi
  • psi_dpsi[3] = dpsi/dz

This is a SIMD function.

Parameters
psi_dpsipointer for storing psi [V*s*m^-1] and its derivatives
rR coordinate [m]
phiphi coordinate [rad]
zz coordinate [m]
ttime coordinate [s]
Bdatapointer to magnetic field data struct
Returns
Non-zero a5err value if evaluation failed, zero otherwise

Definition at line 265 of file B_field.c.

◆ B_field_eval_rho()

DECLARE_TARGET_END a5err B_field_eval_rho ( real rho[2],
real psi,
B_field_data * Bdata )

Evaluate normalized poloidal flux rho and its psi derivative.

This function evaluates the normalized poloidal flux rho at the given coordinates. The rho is evaluated from psi as:

\begin{equation*}
\rho = \sqrt{ \frac{\psi - \psi_0}{\psi_1 - \psi_0} },
\end{equation*}

where $\psi_0$ is psi at magnetic axis and $\psi_1$ is psi at separatrix.

This is a SIMD function.

Parameters
rhopointer where rho value will be stored
psipoloidal flux from which rho is evaluated
Bdatapointer to magnetic field data struct
Returns
Non-zero a5err value if evaluation failed, zero otherwise

Definition at line 327 of file B_field.c.

◆ B_field_eval_rho_drho()

DECLARE_TARGET_END a5err B_field_eval_rho_drho ( real rho_drho[4],
real r,
real phi,
real z,
B_field_data * Bdata )

Evaluate normalized poloidal flux rho and its derivatives.

This function evaluates the normalized poloidal flux rho at the given coordinates. The rho is evaluated from psi as:

\begin{equation*}
\rho = \sqrt{ \frac{\psi - \psi_0}{\psi_1 - \psi_0} },
\end{equation*}

where $\psi_0$ is psi at magnetic axis and $\psi_1$ is psi at separatrix.

The values are stored in the given array as:

  • rho_drho[0] = rho
  • rho_drho[1] = drho/dr
  • rho_drho[2] = drho/dphi
  • rho_drho[3] = drho/dz

This is a SIMD function.

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 410 of file B_field.c.

◆ B_field_eval_B()

DECLARE_TARGET_END a5err B_field_eval_B ( real B[3],
real r,
real phi,
real z,
real t,
B_field_data * Bdata )

Evaluate magnetic field.

This function evaluates the magnetic field at the given coordinates.

The values are stored in the given array as:

  • B[0] = BR
  • B[1] = Bphi
  • B[2] = Bz

This is a SIMD function.

Parameters
Bpointer to array where magnetic field values are stored
rR coordinate [m]
phiphi coordinate [deg]
zz coordinate [m]
ttime coordinate [s]
Bdatapointer to magnetic field data struct
Returns
Non-zero a5err value if evaluation failed, zero otherwise

Definition at line 472 of file B_field.c.

◆ B_field_eval_B_dB()

DECLARE_TARGET_END a5err B_field_eval_B_dB ( real B_dB[15],
real r,
real phi,
real z,
real t,
B_field_data * Bdata )

Evaluate magnetic field and its derivatives.

This function evaluates the magnetic field and its derivatives at the given coordinates.

The values are stored in the given array as:

  • B[0] = BR
  • B[1] = dBR/dR
  • B[2] = dBR/dphi
  • B[3] = dBR/dz
  • B[4] = Bphi
  • B[5] = dBphi/dR
  • B[6] = dBphi/dphi
  • B[7] = dBphi/dz
  • B[8] = Bz
  • B[9] = dBz/dR
  • B[10] = dBz/dphi
  • B[11] = dBz/dz
  • B[12] = dBR/dt
  • B[13] = dBphi/dt
  • B[14] = dBz/dt

This is a SIMD function.

Parameters
B_dBpointer to array where the field and its derivatives are stored
rR coordinate [m]
phiphi coordinate [deg]
zz coordinate [m]
ttime coordinate [s]
Bdatapointer to magnetic field data struct
Returns
Non-zero a5err value if evaluation failed, zero otherwise

Definition at line 547 of file B_field.c.

◆ B_field_get_axis_rz()

DECLARE_TARGET_END a5err B_field_get_axis_rz ( real rz[2],
B_field_data * Bdata,
real phi )

Return magnetic axis Rz-coordinates.

Returns magnetic axis Rz-coordinates at given toroidal angle.

Parameters
rzpointer where axis R and z [m] values will be stored
Bdatapointer to magnetic field data struct
phiphi coordinate [deg]
Returns
Magnetic axis R-coordinate [m]

Definition at line 599 of file B_field.c.