102 real* coeff_array = (
real*) malloc( (3*NSIZE_COMP3D*B_size
103 + NSIZE_COMP2D*psi_size)*
sizeof(
real));
104 real* B_r = &(coeff_array[0*B_size*NSIZE_COMP3D]);
105 real* B_phi = &(coeff_array[1*B_size*NSIZE_COMP3D]);
106 real* B_z = &(coeff_array[2*B_size*NSIZE_COMP3D]);
107 real* psi = &(coeff_array[3*B_size*NSIZE_COMP3D]);
110 psi, *offload_array + 3*B_size,
117 B_r, *offload_array + 0*B_size,
126 B_phi, *offload_array + 1*B_size,
135 B_z, *offload_array + 2*B_size,
144 print_err(
"Error: Failed to initialize splines.\n");
149 free(*offload_array);
150 *offload_array = coeff_array;
152 + NSIZE_COMP3D*B_size*3;
156 B_3DS_init(&Bdata, offload_data, *offload_array);
157 real psival[1], Bval[3];
163 print_err(
"Error: Initialization failed.\n");
168 printf(
"\n3D magnetic field (B_3DS)\n");
188 psival[0], offload_data->
psi0);
190 "B_R = %3.3f B_phi = %3.3f B_z = %3.3f\n",
191 Bval[0], Bval[1], Bval[2]);
203 real** offload_array) {
204 free(*offload_array);
205 *offload_array = NULL;
216 real* offload_array) {
218 int B_size = NSIZE_COMP3D * offload_data->
Bgrid_n_r
222 Bdata->psi0 = offload_data->
psi0;
223 Bdata->psi1 = offload_data->
psi1;
224 Bdata->axis_r = offload_data->
axis_r;
225 Bdata->axis_z = offload_data->
axis_z;
313 real psi_dpsi_temp[6];
317 psi_dpsi[0] = psi_dpsi_temp[0];
318 psi_dpsi[1] = psi_dpsi_temp[1];
320 psi_dpsi[3] = psi_dpsi_temp[2];
352 real delta = Bdata->psi1 - Bdata->psi0;
353 if( (psi_dpsi[0] - Bdata->psi0) / delta < 0 ) {
358 rho_drho[0] = sqrt(fabs((psi_dpsi[0] - Bdata->psi0) / delta));
360 rho_drho[1] = psi_dpsi[1] / (2*delta*rho_drho[0]);
362 rho_drho[3] = psi_dpsi[2] / (2*delta*rho_drho[0]);
395 B[0] = B[0] - psi_dpsi[2]/r;
396 B[2] = B[2] + psi_dpsi[1]/r;
406 check += ((B[0]*B[0] + B[1]*B[1] + B[2]*B[2]) == 0);
432 B_dB[0] = B_dB_temp[0];
433 B_dB[1] = B_dB_temp[1];
434 B_dB[2] = B_dB_temp[2];
435 B_dB[3] = B_dB_temp[3];
438 B_dB[4] = B_dB_temp[0];
439 B_dB[5] = B_dB_temp[1];
440 B_dB[6] = B_dB_temp[2];
441 B_dB[7] = B_dB_temp[3];
444 B_dB[8] = B_dB_temp[0];
445 B_dB[9] = B_dB_temp[1];
446 B_dB[10] = B_dB_temp[2];
447 B_dB[11] = B_dB_temp[3];
458 B_dB[0] = B_dB[0] - psi_dpsi[2]/r;
459 B_dB[1] = B_dB[1] + psi_dpsi[2]/(r*r)-psi_dpsi[5]/r;
460 B_dB[3] = B_dB[3] - psi_dpsi[4]/r;
461 B_dB[8] = B_dB[8] + psi_dpsi[1]/r;
462 B_dB[9] = B_dB[9] - psi_dpsi[1]/(r*r) + psi_dpsi[3]/r;
463 B_dB[11] = B_dB[11] + psi_dpsi[5]/r;
473 check += ((B_dB[0]*B_dB[0] + B_dB[4]*B_dB[4] + B_dB[8]*B_dB[8]) == 0);
491 rz[0] = Bdata->axis_r;
492 rz[1] = Bdata->axis_z;
void B_3DS_free_offload(B_3DS_offload_data *offload_data, real **offload_array)
Free offload array.
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.
int B_3DS_init_offload(B_3DS_offload_data *offload_data, real **offload_array)
Initialize magnetic field offload data.
void B_3DS_init(B_3DS_data *Bdata, B_3DS_offload_data *offload_data, real *offload_array)
Initialize magnetic field data struct on target.
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.
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.
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.
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_init_coeff(real *c, 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)
Calculate tricubic spline interpolation coefficients for 3D 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.
int interp2Dcomp_init_coeff(real *c, 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)
Calculate bicubic spline interpolation coefficients for scalar 2D data.
void interp3Dcomp_init_spline(interp3D_data *str, real *c, 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)
Initialize a tricubic spline.
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.
void interp2Dcomp_init_spline(interp2D_data *str, real *c, int n_x, int n_y, int bc_x, int bc_y, real x_min, real x_max, real y_min, real y_max)
Initialize a bicubic spline.
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 on the target
3D magnetic field parameters on the host