70 real** offload_array) {
74 int datasize = offload_data->
n_r*offload_data->
n_z;
77 real* coeff_array = (
real*) malloc(4*NSIZE_COMP2D*datasize*
sizeof(
real));
78 real* psi = &(coeff_array[0*datasize*NSIZE_COMP2D]);
79 real* B_r = &(coeff_array[1*datasize*NSIZE_COMP2D]);
80 real* B_phi = &(coeff_array[2*datasize*NSIZE_COMP2D]);
81 real* B_z = &(coeff_array[3*datasize*NSIZE_COMP2D]);
85 psi, *offload_array + 0*datasize,
86 offload_data->
n_r, offload_data->
n_z,
92 B_r, *offload_array + 1*datasize,
93 offload_data->
n_r, offload_data->
n_z,
99 B_phi, *offload_array + 2*datasize,
100 offload_data->
n_r, offload_data->
n_z,
106 B_z, *offload_array + 3*datasize,
107 offload_data->
n_r, offload_data->
n_z,
113 print_err(
"Error: Failed to initialize splines.\n");
118 free(*offload_array);
119 *offload_array = coeff_array;
126 B_2DS_init(&Bdata, offload_data, *offload_array);
127 real psival[1], Bval[3];
133 print_err(
"Error: Initialization failed.\n");
139 "\n2D magnetic field (B_2DS)\n"
140 "Grid: nR = %4.d Rmin = %3.3f Rmax = %3.3f\n"
141 " nz = %4.d zmin = %3.3f zmax = %3.3f\n"
142 "Psi at magnetic axis (%1.3f m, %1.3f m)\n"
143 "%3.3f (evaluated)\n%3.3f (given)\n"
144 "Magnetic field on axis:\n"
145 "B_R = %3.3f B_phi = %3.3f B_z = %3.3f\n",
151 psival[0], offload_data->
psi0,
152 Bval[0], Bval[1], Bval[2]);
164 real** offload_array) {
165 free(*offload_array);
166 *offload_array = NULL;
177 real* offload_array) {
182 Bdata->psi0 = offload_data->
psi0;
183 Bdata->psi1 = offload_data->
psi1;
184 Bdata->axis_r = offload_data->
axis_r;
185 Bdata->axis_z = offload_data->
axis_z;
196 offload_data->
z_max);
205 offload_data->
z_max);
214 offload_data->
z_max);
223 offload_data->
z_max);
264 real psi_dpsi_temp[6];
267 psi_dpsi[0] = psi_dpsi_temp[0];
268 psi_dpsi[1] = psi_dpsi_temp[1];
270 psi_dpsi[3] = psi_dpsi_temp[2];
304 real delta = Bdata->psi1 - Bdata->psi0;
305 if( !err && (psi_dpsi[0] - Bdata->psi0) / delta < 0 ) {
310 rho_drho[0] = sqrt((psi_dpsi[0] - Bdata->psi0) / delta);
311 rho_drho[1] = psi_dpsi[1] / (2*delta*rho_drho[0]);
313 rho_drho[3] = psi_dpsi[2] / (2*delta*rho_drho[0]);
345 B[0] = B[0] - psi_dpsi[2]/r;
346 B[2] = B[2] + psi_dpsi[1]/r;
356 check += ((B[0]*B[0] + B[1]*B[1] + B[2]*B[2]) == 0);
383 B_dB[0] = B_dB_temp[0];
384 B_dB[1] = B_dB_temp[1];
386 B_dB[3] = B_dB_temp[2];
390 B_dB[4] = B_dB_temp[0];
391 B_dB[5] = B_dB_temp[1];
393 B_dB[7] = B_dB_temp[2];
397 B_dB[8] = B_dB_temp[0];
398 B_dB[9] = B_dB_temp[1];
400 B_dB[11] = B_dB_temp[2];
413 B_dB[0] = B_dB[0] - psi_dpsi[2]/r;
414 B_dB[1] = B_dB[1] + psi_dpsi[2]/(r*r)-psi_dpsi[5]/r;
415 B_dB[3] = B_dB[3] - psi_dpsi[4]/r;
416 B_dB[8] = B_dB[8] + psi_dpsi[1]/r;
417 B_dB[9] = B_dB[9] - psi_dpsi[1]/(r*r) + psi_dpsi[3]/r;
418 B_dB[11] = B_dB[11] + psi_dpsi[5]/r;
428 check += ((B_dB[0]*B_dB[0] + B_dB[4]*B_dB[4] + B_dB[8]*B_dB[8]) == 0);
446 rz[0] = Bdata->axis_r;
447 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.
void B_2DS_free_offload(B_2DS_offload_data *offload_data, real **offload_array)
Free offload array.
void B_2DS_init(B_2DS_data *Bdata, B_2DS_offload_data *offload_data, real *offload_array)
Initialize magnetic field data struct on target.
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.
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.
int B_2DS_init_offload(B_2DS_offload_data *offload_data, real **offload_array)
Initialize magnetic field offload 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 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 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.
splinesize
Number of coefficients stored for each data point.
Macros for printing console output.
#define print_out(v,...)
Print to standard output.
#define print_err(...)
Print to standard error.
2D magnetic field parameters on the target
2D magnetic field parameters that will be offloaded to target