82 int p_n_r,
real p_r_min,
real p_r_max,
83 int p_n_phi,
real p_phi_min,
real p_phi_max,
84 int p_n_z,
real p_z_min,
real p_z_max,
85 int b_n_r,
real b_r_min,
real b_r_max,
86 int b_n_phi,
real b_phi_min,
real b_phi_max,
87 int b_n_z,
real b_z_min,
real b_z_max,
88 int naxis,
real axis_min,
real axis_max,
98 p_r_min, p_r_max, p_phi_min, p_phi_max,
101 print_err(
"Error: Failed to initialize splines.\n");
105 &data->
B_r, B_r, b_n_r, b_n_phi, b_n_z,
107 b_r_min, b_r_max, b_phi_min, b_phi_max, b_z_min, b_z_max);
109 print_err(
"Error: Failed to initialize splines.\n");
113 &data->
B_phi, B_phi, b_n_r, b_n_phi, b_n_z,
115 b_r_min, b_r_max, b_phi_min, b_phi_max, b_z_min, b_z_max);
117 print_err(
"Error: Failed to initialize splines.\n");
121 &data->
B_z, B_z, b_n_r, b_n_phi, b_n_z,
123 b_r_min, b_r_max, b_phi_min, b_phi_max, b_z_min, b_z_max);
125 print_err(
"Error: Failed to initialize splines.\n");
131 for(
int i = 0; i < naxis; i++) {
139 real psival[1], Bval[3], axis[2];
144 print_err(
"Error: Initialization failed.\n");
148 printf(
"\nStellarator magnetic field (B_STS)\n");
150 p_n_r, p_r_min, p_r_max);
152 p_n_z, p_z_min, p_z_max);
156 b_n_r, b_r_min, b_r_max);
158 b_n_z, b_z_min, b_z_max);
164 psival[0], data->
psi0);
166 "B_R = %3.3f B_phi = %3.3f B_z = %3.3f\n",
167 Bval[0], Bval[1], Bval[2]);
219#ifdef B_STS_CLAMP_RHO_NONNEGATIVE
220 if ( psi[0] < Bdata->psi0 ){
221 psi[0] = Bdata->psi0;
248 real psi_dpsi_temp[10];
253 psi_dpsi[0] = psi_dpsi_temp[0];
254 psi_dpsi[1] = psi_dpsi_temp[1];
255 psi_dpsi[2] = psi_dpsi_temp[2];
256 psi_dpsi[3] = psi_dpsi_temp[3];
258#ifdef B_STS_CLAMP_RHO_NONNEGATIVE
259 if ( psi_dpsi_temp[0] < Bdata->psi0 ){
260 psi_dpsi[0] = Bdata->psi0;
297 real delta = Bdata->psi1 - Bdata->psi0;
298 if( (psi_dpsi[0] - Bdata->psi0) / delta <= 0 ) {
299#ifdef B_STS_CLAMP_RHO_NONNEGATIVE
315 rho_drho[0] = sqrt( (psi_dpsi[0] - Bdata->psi0) / delta );
317 rho_drho[1] = psi_dpsi[1] / (2*delta*rho_drho[0]);
318 rho_drho[2] = psi_dpsi[2] / (2*delta*rho_drho[0]);
319 rho_drho[3] = psi_dpsi[3] / (2*delta*rho_drho[0]);
350 check += ((B[0]*B[0] + B[1]*B[1] + B[2]*B[2]) == 0);
378 B_dB[0] = B_dB_temp[0];
379 B_dB[1] = B_dB_temp[1];
380 B_dB[2] = B_dB_temp[2];
381 B_dB[3] = B_dB_temp[3];
385 B_dB[4] = B_dB_temp[0];
386 B_dB[5] = B_dB_temp[1];
387 B_dB[6] = B_dB_temp[2];
388 B_dB[7] = B_dB_temp[3];
392 B_dB[8] = B_dB_temp[0];
393 B_dB[9] = B_dB_temp[1];
394 B_dB[10] = B_dB_temp[2];
395 B_dB[11] = B_dB_temp[3];
404 check += ((B_dB[0]*B_dB[0] + B_dB[4]*B_dB[4] + B_dB[8]*B_dB[8]) == 0);
void B_STS_offload(B_STS_data *data)
Offload data to the accelerator.
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.
int B_STS_init(B_STS_data *data, int p_n_r, real p_r_min, real p_r_max, int p_n_phi, real p_phi_min, real p_phi_max, int p_n_z, real p_z_min, real p_z_max, int b_n_r, real b_r_min, real b_r_max, int b_n_phi, real b_phi_min, real b_phi_max, int b_n_z, real b_z_min, real b_z_max, int naxis, real axis_min, real axis_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.
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.
void B_STS_free(B_STS_data *data)
Free allocated resources.
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_get_axis_rz(real rz[2], B_STS_data *Bdata, real phi)
Return magnetic axis Rz-coordinates.
a5err B_STS_eval_B(real B[3], real r, real phi, real z, B_STS_data *Bdata)
Evaluate magnetic field.
Main header file for ASCOT5.
Header file containing physical and mathematical constants.
unsigned long int a5err
Simulation error flag.
static DECLARE_TARGET_SIMD a5err error_raise(error_type type, int line, error_file file)
Raise a new error.
Spline interpolation library.
DECLARE_TARGET_END a5err interp3Dcomp_eval_f(real *f, interp3D_data *str, real x, real y, real z)
Evaluate interpolated value of 3D scalar field.
int interp3Dcomp_setup(interp3D_data *str, real *f, int n_x, int n_y, int n_z, int bc_x, int bc_y, int bc_z, real x_min, real x_max, real y_min, real y_max, real z_min, real z_max)
Set up splines to interpolate 3D scalar data.
DECLARE_TARGET_END a5err interp3Dcomp_eval_df(real *f_df, interp3D_data *str, real x, real y, real z)
Evaluate interpolated value of 3D field and 1st and 2nd derivatives.
Linear interpolation library.
int linint1D_eval_f(real *f, linint1D_data *str, real x)
Evaluate interpolated value of 1D scalar field.
void linint1D_init(linint1D_data *str, real *c, int n_x, int bc_x, real x_min, real x_max)
Initialize linear interpolation struct for scalar 1D data.
#define math_rad2deg(a)
Convert radians to degrees.
Macros for printing console output.
#define print_out(v,...)
Print to standard output.
#define print_err(...)
Print to standard error.
stellarator magnetic field parameters on the target