106 int axis_size = offload_data->
n_axis;
109 real* coeff_array = (
real*) malloc( (3*NSIZE_COMP3D*B_size
110 + NSIZE_COMP3D*psi_size
111 + 2*axis_size)*
sizeof(
real));
112 real* B_r = &(coeff_array[0*B_size*NSIZE_COMP3D]);
113 real* B_phi = &(coeff_array[1*B_size*NSIZE_COMP3D]);
114 real* B_z = &(coeff_array[2*B_size*NSIZE_COMP3D]);
115 real* psi = &(coeff_array[3*B_size*NSIZE_COMP3D]);
116 real* axis_r = &(coeff_array[(3*B_size + psi_size)*NSIZE_COMP3D]);
117 real* axis_z = &(coeff_array[(3*B_size + psi_size)*NSIZE_COMP3D
121 psi, *offload_array + 3*B_size,
130 B_r, *offload_array + 0*B_size,
139 B_phi, *offload_array + 1*B_size,
148 B_z, *offload_array + 2*B_size,
157 print_err(
"Error: Failed to initialize splines.\n");
161 for(
int i = 0; i < axis_size; i++) {
162 axis_r[i] = (*offload_array)[3*B_size + psi_size + i];
163 axis_z[i] = (*offload_array)[3*B_size + psi_size + axis_size + i];
167 free(*offload_array);
168 *offload_array = coeff_array;
170 + NSIZE_COMP3D*psi_size
175 B_STS_init(&Bdata, offload_data, *offload_array);
176 real psival[1], Bval[3], axis[2];
183 print_err(
"Error: Initialization failed.\n");
187 printf(
"\nStellarator magnetic field (B_STS)\n");
211 psival[0], offload_data->
psi0);
213 "B_R = %3.3f B_phi = %3.3f B_z = %3.3f\n",
214 Bval[0], Bval[1], Bval[2]);
226 free(*offload_array);
227 *offload_array = NULL;
238 real* offload_array) {
244 int axis_size = offload_data->
n_axis;
247 Bdata->psi0 = offload_data->
psi0;
248 Bdata->psi1 = offload_data->
psi1;
301 &(offload_array[3*B_size + psi_size]),
306 &(offload_array[3*B_size + psi_size + axis_size]),
329#ifdef B_STS_CLAMP_RHO_NONNEGATIVE
330 if ( psi[0] < Bdata->psi0 ){
331 psi[0] = Bdata->psi0;
358 real psi_dpsi_temp[10];
363 psi_dpsi[0] = psi_dpsi_temp[0];
364 psi_dpsi[1] = psi_dpsi_temp[1];
365 psi_dpsi[2] = psi_dpsi_temp[2];
366 psi_dpsi[3] = psi_dpsi_temp[3];
368#ifdef B_STS_CLAMP_RHO_NONNEGATIVE
369 if ( psi_dpsi_temp[0] < Bdata->psi0 ){
370 psi_dpsi[0] = Bdata->psi0;
407 real delta = Bdata->psi1 - Bdata->psi0;
408 if( (psi_dpsi[0] - Bdata->psi0) / delta <= 0 ) {
409#ifdef B_STS_CLAMP_RHO_NONNEGATIVE
425 rho_drho[0] = sqrt( (psi_dpsi[0] - Bdata->psi0) / delta );
427 rho_drho[1] = psi_dpsi[1] / (2*delta*rho_drho[0]);
428 rho_drho[2] = psi_dpsi[2] / (2*delta*rho_drho[0]);
429 rho_drho[3] = psi_dpsi[3] / (2*delta*rho_drho[0]);
460 check += ((B[0]*B[0] + B[1]*B[1] + B[2]*B[2]) == 0);
488 B_dB[0] = B_dB_temp[0];
489 B_dB[1] = B_dB_temp[1];
490 B_dB[2] = B_dB_temp[2];
491 B_dB[3] = B_dB_temp[3];
495 B_dB[4] = B_dB_temp[0];
496 B_dB[5] = B_dB_temp[1];
497 B_dB[6] = B_dB_temp[2];
498 B_dB[7] = B_dB_temp[3];
502 B_dB[8] = B_dB_temp[0];
503 B_dB[9] = B_dB_temp[1];
504 B_dB[10] = B_dB_temp[2];
505 B_dB[11] = B_dB_temp[3];
514 check += ((B_dB[0]*B_dB[0] + B_dB[4]*B_dB[4] + B_dB[8]*B_dB[8]) == 0);
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.
void B_STS_free_offload(B_STS_offload_data *offload_data, real **offload_array)
Free offload array.
void B_STS_init(B_STS_data *Bdata, B_STS_offload_data *offload_data, real *offload_array)
Initialize magnetic field data struct on target.
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.
int B_STS_init_offload(B_STS_offload_data *offload_data, real **offload_array)
Initialize magnetic field offload data.
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_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.
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.
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
stellarator magnetic field parameters on the host