107 int p_n_r,
real p_r_min,
real p_r_max,
108 int p_n_z,
real p_z_min,
real p_z_max,
109 int b_n_r,
real b_r_min,
real b_r_max,
110 int b_n_phi,
real b_phi_min,
real b_phi_max,
111 int b_n_z,
real b_z_min,
real b_z_max,
124 p_r_min, p_r_max, p_z_min, p_z_max);
126 print_err(
"Error: Failed to initialize splines.\n");
131 b_r_min, b_r_max, b_phi_min, b_phi_max,
134 print_err(
"Error: Failed to initialize splines.\n");
139 b_r_min, b_r_max, b_phi_min, b_phi_max,
142 print_err(
"Error: Failed to initialize splines.\n");
147 b_r_min, b_r_max, b_phi_min, b_phi_max,
150 print_err(
"Error: Failed to initialize splines.\n");
155 real psival[1], Bval[3];
159 print_err(
"Error: Initialization failed.\n");
164 printf(
"\n3D magnetic field (B_3DS)\n");
166 p_n_r, p_r_min, p_r_max);
168 p_n_z, p_z_min, p_z_max);
170 b_n_r, b_r_min, b_r_max);
172 b_n_z, b_z_min, b_z_max);
178 psival[0], data->
psi0);
180 "B_R = %3.3f B_phi = %3.3f B_z = %3.3f\n",
181 Bval[0], Bval[1], Bval[2]);
252 real psi_dpsi_temp[6];
256 psi_dpsi[0] = psi_dpsi_temp[0];
257 psi_dpsi[1] = psi_dpsi_temp[1];
259 psi_dpsi[3] = psi_dpsi_temp[2];
291 real delta = Bdata->psi1 - Bdata->psi0;
292 if( (psi_dpsi[0] - Bdata->psi0) / delta < 0 ) {
297 rho_drho[0] = sqrt(fabs((psi_dpsi[0] - Bdata->psi0) / delta));
299 rho_drho[1] = psi_dpsi[1] / (2*delta*rho_drho[0]);
301 rho_drho[3] = psi_dpsi[2] / (2*delta*rho_drho[0]);
334 B[0] = B[0] - psi_dpsi[2]/r;
335 B[2] = B[2] + psi_dpsi[1]/r;
345 check += ((B[0]*B[0] + B[1]*B[1] + B[2]*B[2]) == 0);
371 B_dB[0] = B_dB_temp[0];
372 B_dB[1] = B_dB_temp[1];
373 B_dB[2] = B_dB_temp[2];
374 B_dB[3] = B_dB_temp[3];
377 B_dB[4] = B_dB_temp[0];
378 B_dB[5] = B_dB_temp[1];
379 B_dB[6] = B_dB_temp[2];
380 B_dB[7] = B_dB_temp[3];
383 B_dB[8] = B_dB_temp[0];
384 B_dB[9] = B_dB_temp[1];
385 B_dB[10] = B_dB_temp[2];
386 B_dB[11] = B_dB_temp[3];
397 B_dB[0] = B_dB[0] - psi_dpsi[2]/r;
398 B_dB[1] = B_dB[1] + psi_dpsi[2]/(r*r)-psi_dpsi[5]/r;
399 B_dB[3] = B_dB[3] - psi_dpsi[4]/r;
400 B_dB[8] = B_dB[8] + psi_dpsi[1]/r;
401 B_dB[9] = B_dB[9] - psi_dpsi[1]/(r*r) + psi_dpsi[3]/r;
402 B_dB[11] = B_dB[11] + psi_dpsi[5]/r;
412 check += ((B_dB[0]*B_dB[0] + B_dB[4]*B_dB[4] + B_dB[8]*B_dB[8]) == 0);
430 rz[0] = Bdata->axis_r;
431 rz[1] = Bdata->axis_z;
a5err B_3DS_eval_rho_drho(real rho_drho[4], real r, real phi, real z, B_3DS_data *Bdata)
Evaluate normalized poloidal flux rho and its derivatives.
a5err B_3DS_eval_B(real B[3], real r, real phi, real z, B_3DS_data *Bdata)
Evaluate magnetic field.
a5err B_3DS_eval_psi_dpsi(real psi_dpsi[4], real r, real phi, real z, B_3DS_data *Bdata)
Evaluate poloidal flux psi and its derivatives.
void B_3DS_free(B_3DS_data *data)
Free allocated resources.
a5err B_3DS_get_axis_rz(real rz[2], B_3DS_data *Bdata)
Return magnetic axis R-coordinate.
a5err B_3DS_eval_psi(real *psi, real r, real phi, real z, B_3DS_data *Bdata)
Evaluate poloidal flux psi.
void B_3DS_offload(B_3DS_data *data)
Offload data to the accelerator.
a5err B_3DS_eval_B_dB(real B_dB[12], real r, real phi, real z, B_3DS_data *Bdata)
Evaluate magnetic field and its derivatives.
int B_3DS_init(B_3DS_data *data, int p_n_r, real p_r_min, real p_r_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, 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.
Main header file for ASCOT5.
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.
int interp2Dcomp_setup(interp2D_data *str, real *f, int n_x, int n_y, int bc_x, int bc_y, real x_min, real x_max, real y_min, real y_max)
Set up splines to interpolate 2D scalar data.
DECLARE_TARGET_END a5err interp2Dcomp_eval_df(real *f_df, interp2D_data *str, real x, real y)
Evaluate interpolated value and 1st and 2nd derivatives of 2D field.
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.
DECLARE_TARGET_END a5err interp2Dcomp_eval_f(real *f, interp2D_data *str, real x, real y)
Evaluate interpolated value of a 2D field.
#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.
3D magnetic field parameters