69 r_min, r_max, z_min, z_max);
71 print_err(
"Error: Failed to initialize splines.\n");
75 r_min, r_max, z_min, z_max);
77 print_err(
"Error: Failed to initialize splines.\n");
83 print_err(
"Error: Failed to initialize splines.\n");
87 r_min, r_max, z_min, z_max);
89 print_err(
"Error: Failed to initialize splines.\n");
94 real psival[1], Bval[3];
98 print_err(
"Error: Initialization failed.\n");
104 "\n2D magnetic field (B_2DS)\n"
105 "Grid: nR = %4.d Rmin = %3.3f Rmax = %3.3f\n"
106 " nz = %4.d zmin = %3.3f zmax = %3.3f\n"
107 "Psi at magnetic axis (%1.3f m, %1.3f m)\n"
108 "%3.3f (evaluated)\n%3.3f (given)\n"
109 "Magnetic field on axis:\n"
110 "B_R = %3.3f B_phi = %3.3f B_z = %3.3f\n",
114 psival[0], data->
psi0,
115 Bval[0], Bval[1], Bval[2]);
185 real psi_dpsi_temp[6];
188 psi_dpsi[0] = psi_dpsi_temp[0];
189 psi_dpsi[1] = psi_dpsi_temp[1];
191 psi_dpsi[3] = psi_dpsi_temp[2];
225 real delta = Bdata->psi1 - Bdata->psi0;
226 if( !err && (psi_dpsi[0] - Bdata->psi0) / delta < 0 ) {
231 rho_drho[0] = sqrt((psi_dpsi[0] - Bdata->psi0) / delta);
232 rho_drho[1] = psi_dpsi[1] / (2*delta*rho_drho[0]);
234 rho_drho[3] = psi_dpsi[2] / (2*delta*rho_drho[0]);
266 B[0] = B[0] - psi_dpsi[2]/r;
267 B[2] = B[2] + psi_dpsi[1]/r;
277 check += ((B[0]*B[0] + B[1]*B[1] + B[2]*B[2]) == 0);
304 B_dB[0] = B_dB_temp[0];
305 B_dB[1] = B_dB_temp[1];
307 B_dB[3] = B_dB_temp[2];
311 B_dB[4] = B_dB_temp[0];
312 B_dB[5] = B_dB_temp[1];
314 B_dB[7] = B_dB_temp[2];
318 B_dB[8] = B_dB_temp[0];
319 B_dB[9] = B_dB_temp[1];
321 B_dB[11] = B_dB_temp[2];
334 B_dB[0] = B_dB[0] - psi_dpsi[2]/r;
335 B_dB[1] = B_dB[1] + psi_dpsi[2]/(r*r)-psi_dpsi[5]/r;
336 B_dB[3] = B_dB[3] - psi_dpsi[4]/r;
337 B_dB[8] = B_dB[8] + psi_dpsi[1]/r;
338 B_dB[9] = B_dB[9] - psi_dpsi[1]/(r*r) + psi_dpsi[3]/r;
339 B_dB[11] = B_dB[11] + psi_dpsi[5]/r;
349 check += ((B_dB[0]*B_dB[0] + B_dB[4]*B_dB[4] + B_dB[8]*B_dB[8]) == 0);
367 rz[0] = Bdata->axis_r;
368 rz[1] = Bdata->axis_z;
a5err B_2DS_eval_psi(real *psi, real r, real phi, real z, B_2DS_data *Bdata)
Evaluate poloidal flux psi.
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.
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.
void B_2DS_offload(B_2DS_data *data)
Offload data to the accelerator.
void B_2DS_free(B_2DS_data *data)
Free allocated resources.
a5err B_2DS_get_axis_rz(real rz[2], B_2DS_data *Bdata)
Return magnetic axis R-coordinate.
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.
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.
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 interp2Dcomp_eval_f(real *f, interp2D_data *str, real x, real y)
Evaluate interpolated value of a 2D field.
Macros for printing console output.
#define print_out(v,...)
Print to standard output.
#define print_err(...)
Print to standard error.
2D magnetic field parameters